NingG +

java中输出日志log4j和slf4j

几个要点:

slf4j

几点:

示例代码如下:

...
// 声明
private static final Logger logger = LoggerFactory.getLogger(SpoolDirectorySource.class);
...

// 记录日志
logger.info("SpoolingDirectorySource source starting with directory: {}", spoolDirectory);
...

// 不同级别日志
if (logger.isDebugEnabled()) {
  logger.debug("Initializing {} with directory={}, metaDir={}, " +
	  "deserializer={}",
	  new Object[] { ReliableSpoolingFileEventReader.class.getSimpleName(),
	  spoolDirectory, trackerDirPath, deserializerType });
}

思考:几点:

参考来源

Top