2

I want to decorate logger like below:

public class CustomLogger implements org.slf4j.Logger {
    private final Logger logger;
    public CustomLogger(Class clazz) {
        logger = getLoggerInLogback(clazz);
    }
...
}

When I call org.slf4j.LoggerFactory.getLogger(clazz), I want this method to return a instance of CustomLogger. In this way, I can add additional behavior to logger without changing code.

But how can I make the method to return a instance of CustomLogger?

ayaya
  • 163
  • 1
  • 1
  • 8
  • I think LoggerFactory creates a specific instance and you need your own factory. See similar question https://stackoverflow.com/questions/2653855/implement-custom-logger-with-slf4j – nickolay.laptev Sep 24 '19 at 07:20
  • I just want to decorate loggers in logback but not write my own logger. If I implement the StaticLoggerBinder myself, then I cannot use logback. – ayaya Sep 24 '19 at 07:26

0 Answers0