读书人

spymemcached的log4j日记配置

发布时间: 2013-11-02 19:41:10 作者: rapoo

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 loggerlog4j.logger.net.spy=debug, memcachedLoglog4j.appender.memcachedLog=org.apache.log4j.DailyRollingFileAppenderlog4j.appender.memcachedLog.File=d:/memcached2.loglog4j.appender.memcachedLog.DatePattern='_'yyyy-MM-dd'.log'log4j.appender.memcachedLog.layout=org.apache.log4j.PatternLayoutlog4j.appender.memcachedLog.layout.ConversionPattern=%d %p [%t] | %m%n

读书人网 >开源软件

热点推荐