简体   繁体   中英

Log4j extending Logger

I've extended the Log4J Logger class and created a custom Logger class that decides whether to to log or not.

My pattern layout has the %F and %M parameters to show the class name and method name from where the log was executed.

The problem is that instead of showing the exception caller class and method name it show my custom logger's class and method name!

What do I need to do to shows the correct information?

You need to provide your class as the fully qualified class name for the forcedLog() method.

private static final String FQCN = MyCustomLogger.class.getName();

...

public void info(Object message) {
    if(repository.isDisabled(Level.INFO_INT))
        return;
    if(Level.INFO.isGreaterOrEqual(this.getEffectiveLevel()))
        forcedLog(FQCN, Level.INFO, message, null);
}

....

I'm not sure what you're attempting to filter out, but it might be better to use a filter rather than extend the logger.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM