我是靠谱客的博主 温婉故事,最近开发中收集的这篇文章主要介绍log4j 根据自定义模块名每月新增一个错误信息文件和警告信息文件,觉得挺不错的,现在分享给大家,希望可以做个参考。

概述

log4j 根据模块名每月新增一个错误信息文件和警告信息文件

log4j.properties:

#u5D14u8000u5F3A
u521Bu5EFAu65E5u671F 20151208 u4FEEu6539u65E5u671F20151209 
#u5B9Eu65F6u76D1u63A7u9519u8BEFu4FE1u606F
log4j.logger.realMonitor_ERROR=ERROR ,realMonitor_ERROR
log4j.appender.realMonitor_ERROR=org.apache.log4j.DailyRollingFileAppender
log4j.appender.realMonitor_ERROR.File=./logs/realMonitorError
log4j.appender.realMonitor_ERROR.DatePattern = '('yyyy-MM').log'
log4j.appender.realMonitor_ERROR.Threshold=ERROR
log4j.appender.realMonitor_ERROR.Append=true
log4j.appender.realMonitor_ERROR.layout=org.apache.log4j.PatternLayout
log4j.appender.realMonitor_ERROR.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss}:%m%n
#u5B9Eu65F6u76D1u63A7u8B66u544Au4FE1u606F
log4j.logger.realMonitor_WARN=WARN ,realMonitor_WARN
log4j.appender.realMonitor_WARN=org.apache.log4j.DailyRollingFileAppender
log4j.appender.realMonitor_WARN.File=./logs/realMonitorWarn
log4j.appender.realMonitor_WARN.DatePattern = '('yyyy-MM').log'
log4j.appender.realMonitor_WARN.Threshold=WARN
log4j.appender.realMonitor_WARN.Append=true
log4j.appender.realMonitor_WARN.layout=org.apache.log4j.PatternLayout
log4j.appender.realMonitor_WARN.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss}:%m%n
#u5B9Eu65F6u76D1u63A7
log4j.logger.personLocator_ERROR=ERROR ,personLocator_ERROR
log4j.appender.personLocator_ERROR=org.apache.log4j.DailyRollingFileAppender
log4j.appender.personLocator_ERROR.File=./logs/personLocatorError
log4j.appender.personLocator_ERROR.DatePattern = '('yyyy-MM').log'
log4j.appender.personLocator_ERROR.Threshold=ERROR
log4j.appender.personLocator_ERROR.Append=true
log4j.appender.personLocator_ERROR.layout=org.apache.log4j.PatternLayout
log4j.appender.personLocator_ERROR.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss}:%m%n
#u5B9Eu65F6u76D1u63A7
log4j.logger.personLocator_WARN=WARN ,personLocator_WARN
log4j.appender.personLocator_WARN=org.apache.log4j.DailyRollingFileAppender
log4j.appender.personLocator_WARN.File=./logs/personLocatorWarn
log4j.appender.personLocator_WARN.DatePattern = '('yyyy-MM').log'
log4j.appender.personLocator_WARN.Threshold=WARN
log4j.appender.personLocator_WARN.Append=true
log4j.appender.personLocator_WARN.layout=org.apache.log4j.PatternLayout
log4j.appender.personLocator_WARN.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss}:%m%n
#u6846u67B6
log4j.logger.frame_ERROR=ERROR ,frame_ERROR
log4j.appender.frame_ERROR=org.apache.log4j.DailyRollingFileAppender
log4j.appender.frame_ERROR.File=./logs/frameError
log4j.appender.frame_ERROR.DatePattern = '('yyyy-MM').log'
log4j.appender.frame_ERROR.Threshold=ERROR
log4j.appender.frame_ERROR.Append=true
log4j.appender.frame_ERROR.layout=org.apache.log4j.PatternLayout
log4j.appender.frame_ERROR.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss}:%m%n
#u6846u67B6
log4j.logger.frame_WARN=WARN ,frame_WARN
log4j.appender.frame_WARN=org.apache.log4j.DailyRollingFileAppender
log4j.appender.frame_WARN.File=./logs/frameWarn
log4j.appender.frame_WARN.DatePattern = '('yyyy-MM').log'
log4j.appender.frame_WARN.Threshold=WARN
log4j.appender.frame_WARN.Append=true
log4j.appender.frame_WARN.layout=org.apache.log4j.PatternLayout
log4j.appender.frame_WARN.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss}:%m%n
#u8BBEu5907u7BA1u7406
log4j.logger.deviceManager_ERROR=ERROR ,deviceManager_ERROR
log4j.appender.deviceManager_ERROR=org.apache.log4j.DailyRollingFileAppender
log4j.appender.deviceManager_ERROR.File=./logs/deviceManagerError
log4j.appender.deviceManager_ERROR.DatePattern = '('yyyy-MM').log'
log4j.appender.deviceManager_ERROR.Threshold=ERROR
log4j.appender.deviceManager_ERROR.Append=true
log4j.appender.deviceManager_ERROR.layout=org.apache.log4j.PatternLayout
log4j.appender.deviceManager_ERROR.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss}:%m%n
#u8BBEu5907u7BA1u7406
log4j.logger.deviceManager_WARN=WARN ,deviceManager_WARN
log4j.appender.deviceManager_WARN=org.apache.log4j.DailyRollingFileAppender
log4j.appender.deviceManager_WARN.Threshold=WARN
log4j.appender.deviceManager_WARN.File=./logs/deviceManagerWarn
log4j.appender.deviceManager_WARN.Append=true
log4j.appender.deviceManager_WARN.layout=org.apache.log4j.PatternLayout
log4j.appender.deviceManager_WARN.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss}:%m%n

调用方法:

public class MyLogs {
/**
* 警告日志方法
* @param warningMsg警告信息
* @param className 类名
* @param methodName方法名
*/
public void recordWarningLogs(String warningMsg,String modelName,String className,String methodName){
PropertyConfigurator.configure("res/txt/log4j.properties");
Logger logger = Logger.getLogger(modelName.trim()+"_WARN");
logger.warn(warningMsg+"类名:"+className+" 方法名:"+methodName);
}
/**
* 错误信息方法
* @param errorMsg 错误信息
* @param className 类名
* @param methodName 方法名
*/
public void recordErrorLogs(String errorMsg,String modelName,String className,String methodName){
PropertyConfigurator.configure("res/txt/log4j.properties");
Logger logger = Logger.getLogger(modelName.trim()+"_ERROR");
logger.error(errorMsg+"类名:"+className+" 方法名:"+methodName);
}
}

最后

以上就是温婉故事为你收集整理的log4j 根据自定义模块名每月新增一个错误信息文件和警告信息文件的全部内容,希望文章能够帮你解决log4j 根据自定义模块名每月新增一个错误信息文件和警告信息文件所遇到的程序开发问题。

如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(47)

评论列表共有 0 条评论

立即
投稿
返回
顶部