zoukankan      html  css  js  c++  java
  • Log4j日志文件常用配置

    1日志级别热修改

    web.xml

    ===============================================================================

    <listener>

    <listener-class>

    org.springframework.web.util.Log4jConfigListener

    </listener-class>

    </listener>

    <context-param>

        <param-name>log4jRefreshInterval</param-name>

        <param-value>5000</param-value>

    </context-param>

    ===============================================================================

    Spring的Log4jConfiglistener类会调用Log4j的PropertyConfigurator.configureAndWatch(),将刷新间隔作为参数传入。

    public static void initLogging(String location, long refreshInterval) throws FileNotFoundException {

            String resolvedLocation =SystemPropertyUtils.resolvePlaceholders(location);

            File file = ResourceUtils.getFile(resolvedLocation);

            if (!file.exists()) {

                throw new FileNotFoundException("Log4j config file [" +resolvedLocation + "] not found");

            }

            if(resolvedLocation.toLowerCase().endsWith(XML_FILE_EXTENSION)) {

                DOMConfigurator.configureAndWatch(file.getAbsolutePath(),refreshInterval);

            }

            else {

                PropertyConfigurator.configureAndWatch(file.getAbsolutePath(),refreshInterval);

            }

        }

    2日志文件编码格式

    <appender name="FILEOUT" class="org.apache.log4j.DailyRollingFileAppender">

            <param name="File" value="${vc.log.path}/cdai_ssh.log" />

            <param name="Encoding" value="UTF-8" />

            <layout class="org.apache.log4j.PatternLayout">

                <param name="ConversionPattern" value="[CDAI_SSH]%d{yyy-MM-dd HH:mm:ss}%-5p%m%n" />

            </layout>

            <filter class="org.apache.log4j.varia.LevelRangeFilter">

                <param name="LevelMin" value="DEBUG" />

                <param name="LevelMax" value="DEBUG" />

            </filter>

        </appender>

    3日志文件保留时间

    通过下面配置,可以限制DailyRollingFileAppender保留的文件个数。

    <param name="MaxBackupIndex"value="10"/>

      

  • 相关阅读:
    虚方法和抽象方法
    c#_实现FTP方法(一) FtpWebRequest
    sql server 分页
    5ucms进阶
    图片处理函数
    [转]C++11新特性:Lambda函数
    [STL]for_each详细用法[转]
    [算法]hash table 与 hash map 实现
    [算法]字典树
    [STL]vector的使用[转]
  • 原文地址:https://www.cnblogs.com/xiaomaohai/p/6157769.html
Copyright © 2011-2022 走看看