Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Lombok assign custom logger variable name

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?

like image 443
Nestor Milyaev Avatar asked Jan 16 '19 16:01

Nestor Milyaev


People also ask

What does @Slf4j annotation do?

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.

Does Lombok Slf4j use log4j?

Using Log4j2 Logging with Lombok Now you can use either @Slf4j (recommneded) or @Log4j2 at class to use log4j2 as underlying logging implementation.

What is @Slf4j annotation in spring boot?

@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")); } }

Where do I put Lombok config?

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.


1 Answers

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.

like image 119
user7 Avatar answered Sep 19 '22 08:09

user7