-
Notifications
You must be signed in to change notification settings - Fork 0
User Guide
The first thing you have to do add dependency to your project.
Maven
<dependency>
<groupId>org.loguno</groupId>
<artifactId>loguno-processor</artifactId>
<version>0.0.2</version>
<scope>provided</scope>
</dependency>Gradle
dependencies {
compileOnly 'org.loguno:loguno-processor:0.0.2'
}Then, add dependency for logging framework, cause Loguno only injects logging commands, but you must provide logger yourself. Now it is Slf4j.
Just put the annotation @Loguno.Logger on the class.
The annotation has 3 parameters - logging framework (value), name (name of logger variable) and lazy. For example the annotation:
@Loguno.Logger(value = SLF4J, lazy = true, name = "LOGGER")
public class HelloKitty {creates:
public class HelloKitty {
private static final Logger LOGGER = LazyLoggerFactorySlf4j.getLogger(HelloKitty.class);@Loguno
public void sayMiau(String cat) {By default messages in methods have info level. So here @Loguno equals to @Loguno.INFO. The code after compilation:
public void sayMiau(String cat) {
LOGGER.info("org.loguno.test.HelloKitty.sayMiau Method is called. Parameter {}={}", "cat", cat);
}That is default message. It contains class and method name. So, the parameters are also are logged. You can write your own message, in the annotation and use the one on 5 logging level:
@Loguno.INFO("just info without params")
@Loguno.WARN("just warn with 1 params {}={}")
@Loguno.TRACE("just trace with n params, used for methods [{}={}]")
@Loguno.DEBUG("just debug with 1 params, can be used for local variable {}={}")
@Loguno.ERROR("just error with 1 params, can be used for local variable {}={}")Build the code below and see result .class file:
@Loguno.INFO
public void pussyCat(@Loguno.DEBUG String name, @Loguno.DEBUG("a cat must have {}={}") int legs, Data dateOfBirth, int livesAreLeft) {
@Loguno.TRACE("Kitty's private data {}={}")
String all = Stream.of(name, legs, dateOfBirth, livesAreLeft)
.map(Object::toString)
.collect(Collectors.joining("|"));
}