Lombok assign custom logger variable name

Viewed 8031

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?

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.

Related