Here's how current Lombok logging works:
@Slf4j
public class LogExampleOther {
public static void main(String... args) {
log.error("Something else is wrong here");
}
}
The logger variable is always called log and I see no way to set a custom variable name. What if I want to assign custom logger variable name, like LOGGER. as in:
@Slf4j(loggerName="LOGGER")
public class LogExampleOther {
public static void main(String... args) {
LOGGER.error("Something else is wrong here");
}
}
Is that possible?
Annotation Type Slf4jCauses lombok to generate a logger field. Complete documentation is found at the project lombok features page for lombok log annotations. This annotation is valid for classes and enumerations.
Using Log4j2 Logging with Lombok Now you can use either @Slf4j (recommneded) or @Log4j2 at class to use log4j2 as underlying logging implementation.
@Slf4j generates a logger using the SLF4J API. The logback-classic dependency pulls in other required dependencies. Now, we can annotate our class with @Slf4j: @Slf4j public class Slf4jClient { public static void main(String[] args) { log. error("Error occurred", new RuntimeException("Planned")); } }
Usually, a user of lombok puts a lombok. config file with their preferences in a workspace or project root directory, with the special config. stopBubbling = true key to tell lombok this is your root directory.
From the Lombok documentation, you can use the fieldName
configuration key to give a different name.
lombok.log.fieldName = an identifier (default: log).
The generated logger fieldname is by default 'log', but you can change it to a different name with this setting.
You can find the Lombok configuration system documentation here.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With