简体   繁体   中英

why two instances of logger used in this java class?

In java code I saw two instances of logger like this,

private static final Logger error = LoggerFactory.getLogger("log.error");
private static final Logger warn = LoggerFactory.getLogger("log.warn");

warn instance calling warn method,

warn.warn()

and error instance calls,

error.error()
error.isErrorEnabled()

What is use of using two instances? why not use single instance?

The original author of the code may have wanted to direct warnings and errors to their own files (or other destinations), but didn't understand how to do it via configuration.

Normally you only need a single logger, which you can then configure to perform different things depending on whether you're using warn() or error() .

There's no good reason to use multiple loggers in a single class.

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