buildscript {
repositories {
jcenter() //or mavenCentral()
}
dependencies {
classpath "com.github.luispereira:logthis-plugin:0.5.0"
}
}
apply plugin: "com.lib.logthisannotations" //This will search the annotation and will process them
dependencies {
debugCompile 'com.github.luispereira:logthisannotations:0.5.0'
releaseCompile 'com.github.luispereira:logthisannotations-release:0.5.0'
}
In order to activate the Logger you should call the following method on Application
Logger.init();
From now on the methods with annotation @LogThis will be logged
@LogThis(LoggerLevel.V) //The default value is LoggerLevel.D
public String logThisMethod(String value) {
//...
return "value";
}
logThisMethod("test")
It is also possible to Log every field change:
@LogThis
public String mSampleField = "test1";
(...)
mSampleField = "test2";
Or you can log every field of a class:
@LogThisClassFields(LoggerLevel.I)
public class SampleClass{
private String mValue;
public int otherField = 0;
}
In this case every field on the class will be logged.
Every time you call the method the follow output will appear:
com.lib.logthis D/Class: Method -> logThisMethod(value="test") called
com.lib.logthis D/Class: Method -> logThisMethod(value="test") returned value -> [value]
Method which have the return generic type void will not print the return result.
Or in case of a field log:
com.lib.logthis D/Class: Field ⇢ mSampleField -> oldValue=test1 0 & newValue=test2
Classes fields annotated by @LogThisClassFields will produce the following result:
com.lib.logthis W/com.lib.logthis.MainActivity: ClassField ⇢ i -> oldValue=0 & newValue=1
In order to activate this feature the SDK should be initialized like this:
Logger.init().storeLogs(DIRECTORY_TO_SAVE_THE_LOG);
After this initialization is done the logs will be stored on a file with the name "LogThis.txt" on the specified directory.
Although the user can always avoid to write a determinate log on the annotation by doing:
@LogThis(logger=LoggerLevel.V, write=false) //write to false turns off the store for these logs
public String logThisMethod(String value) {
//...
return "value";
}
- Field annotation to log a local variable when modified