• 关于JBoss的Log4j的输出问题


    使用Web应用中的Log4j配置,而非使用JBoss自身的Log4j配置,具体修改如下:1、修改log4j.xml文件添加<appender-ref ref="fileAppender" />,修改为<logger name="com.travelsky.pss"> <level value="info" /> <appender-ref ref="fileAppender" /></logger>其余<logger name="org.springframework"> 和<logger name="org.hibernate"> 可酌情修改。将<root>中的内容注释掉。生成的log日志以\jboss-eap-5.0\jboss-as\bin\为根目录2、修改web.xml文件增加下面配置 <servlet> <servlet-name>Log4jInit</servlet-name> <servlet-class>com.travelsky.pss.abframe.base.log.Log4jInit</servlet-class> <init-param> <param-name>log4j-init-file</param-name> <param-value>/WEB-INF/classes/log4j.xml</param-value> </init-param> <load-on-startup>1</load-on-startup> </servlet><load-on-startup>中的值如果为2,在Tomcat下正常启动,但JBoss会启动报错。3、增加Log4j的初始化类Log4jInit

    public class Log4jInit extends HttpServlet {

    private static final long serialVersionUID = 1L;

    /**

         * 初始化Log4j的配置

         * @param 

         * Date: 2012-5-15上午10:40:49

         */

    public void init() {

    String prefix = getServletContext().getRealPath("/");

    String file = getInitParameter("log4j-init-file");

    if (file != null) {

    DOMConfigurator.configure(prefix + file);

    //this.listCofig();   // 调试用

    }

    }

    private void listCofig() {

    LoggerRepository logRp = org.apache.log4j.LogManager

    .getLoggerRepository();

    Logger root = logRp.getRootLogger();

    showLogger(root);

    Enumeration<?> enumeration = logRp.getCurrentLoggers();

    if (enumeration != null) {

    while (enumeration.hasMoreElements()) {

    Logger log = (Logger) enumeration.nextElement();

    showLogger(log);

    }

    }

    }

    private void showLogger(Logger log) {

    Enumeration<?> enumeration = log.getAllAppenders();

    if (enumeration != null && enumeration.hasMoreElements()) {

    System.out.println(">>>log name():" + log.getName());

    while (enumeration.hasMoreElements()) {

    Appender append = (Appender) enumeration.nextElement();

    System.out.println(" append ref.getName():" + append.getName());

    }

    System.out.println(">>>log name end");

    }

    }

    }


  • 相关阅读:
    Swift
    Swift
    书籍
    Swift
    Swift
    iOS系统架构
    Reveal真机(越狱)查看任意APP
    Swift
    Swift
    Swift
  • 原文地址:https://www.cnblogs.com/danghuijian/p/4400037.html
Copyright © 2020-2023  润新知