spymemcached的log4j日志配置

spymemcached日志需要在java启动参数中配置
在tomcat中配置方法:
打开tomcat/bin/catalina.sh
找的JAVA_OPTS 变量,添加行
JAVA_OPTS="$JAVA_OPTS -Dnet.spy.log.LoggerImpl=net.spy.memcached.compat.log.Log4JLogger"


在spymemcached中是这样处理的
spy的LoggerFactory类中

  @SuppressWarnings("unchecked")
private void getConstructor() {
Class<? extends Logger> c = DefaultLogger.class;
String className = System.getProperty("net.spy.log.LoggerImpl");

if (className != null) {
try {
c = (Class<? extends Logger>) Class.forName(className);
} catch (NoClassDefFoundError e) {
System.err.println("Warning: " + className
+ " not found while initializing"
+ " net.spy.compat.log.LoggerFactory");
e.printStackTrace();
c = DefaultLogger.class;
} catch (ClassNotFoundException e) {
System.err.println("Warning: " + className
+ " not found while initializing"
+ " net.spy.compat.log.LoggerFactory");
e.printStackTrace();
c = DefaultLogger.class;
}
}

// Find the best constructor
try {
// Try to find a constructor that takes a single string
Class<?>[] args = { String.class };
instanceConstructor = c.getConstructor(args);
} catch (NoSuchMethodException e) {
try {
// Try to find an empty constructor
Class<?>[] args = {};
instanceConstructor = c.getConstructor(args);
} catch (NoSuchMethodException e2) {
System.err.println("Warning: " + className
+ " has no appropriate constructor, using defaults.");

// Try to find a constructor that takes a single string
try {
Class<?>[] args = { String.class };
instanceConstructor = DefaultLogger.class.getConstructor(args);
} catch (NoSuchMethodException e3) {
// This shouldn't happen.
throw new NoSuchMethodError("There used to be a constructor that "
+ "takes a single String on " + DefaultLogger.class + ", but I "
+ "can't find one now.");
} // SOL
} // No empty constructor
} // No constructor that takes a string
} // getConstructor


然后再log4j.properties文件中添加
#memcached logger
log4j.logger.net.spy=debug, memcachedLog
log4j.appender.memcachedLog=org.apache.log4j.DailyRollingFileAppender
log4j.appender.memcachedLog.File=d:/memcached2.log
log4j.appender.memcachedLog.DatePattern='_'yyyy-MM-dd'.log'
log4j.appender.memcachedLog.layout=org.apache.log4j.PatternLayout
log4j.appender.memcachedLog.layout.ConversionPattern=%d %p [%t] | %m%n
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值