zoukankan      html  css  js  c++  java
  • java 日志 log4j

    1.下载jar:log4j-1.2.15.jar

    2.配置文件:log4j.properties

    # Priorities are: DEBUG, INFO, WARN, ERROR, or FATAL.
    log4j.rootCategory=INFO, CONSOLE, FILE
    logs.dir=${catalina.base}/logs/springdemo/
    logs.filename=logs
    fileBufferSize=20480
    
    #log to File
    log4j.appender.FILE=org.apache.log4j.DailyRollingFileAppender
    log4j.appender.FILE.File=D:/${number}/10.logs
    log4j.appender.FILE.encoding=UTF-8
    log4j.appender.FILE.Append=true
    log4j.appender.FILE.LocationInfo=true
    log4j.appender.FILE.DatePattern='.'yyyy-MM-dd'.log'
    log4j.appender.FILE.layout=org.apache.log4j.PatternLayout
    log4j.appender.FILE.layout.ConversionPattern=[%d]: %m %x %n
    log4j.appender.FILE.bufferSize=${fileBufferSize}
    
    # CONSOLE is set to be a ConsoleAppender using a PatternLayout.
    log4j.appender.CONSOLE=org.apache.log4j.ConsoleAppender
    log4j.appender.CONSOLE.Threshold=DEBUG
    log4j.appender.CONSOLE.layout=org.apache.log4j.PatternLayout
    log4j.appender.CONSOLE.layout.ConversionPattern=- %m%n

    3.java类:

    package com.log.test;
    
    import java.text.SimpleDateFormat;
    import java.util.Date;
    
    import org.apache.log4j.Logger;
    import org.apache.log4j.PropertyConfigurator;
    
    public class DemoTest {
    
        static Logger logger = Logger.getLogger(DemoTest.class.getName());
    
        public static void main(String[] args) throws Exception {
            // 格式化时间 年月日
            SimpleDateFormat data = new SimpleDateFormat("YYYYMMdd");
            String format = data.format(new Date());
            // 动态配置路径
            System.setProperty("number", format);//以日期建文件夹
            // 加载配置文件
            PropertyConfigurator.configure("config/log4j.properties");//配置文件的路径
            // 输出日志信息
            logger.debug("HellosdsdWoasdassdasdasdfdsfrld");
        }
    }
  • 相关阅读:
    canvas+js绘制序列帧动画+面向对象
    canvas+js画饼状图
    CSS3 文本溢出问题
    jquery 实现省市二级联动
    jquery将json数据放入表格当中
    css ie6双倍margin现象
    css margin塌陷问题
    css ie浏览器兼容问题
    css 实现文字图片垂直对齐
    css 清楚浮动三种方法
  • 原文地址:https://www.cnblogs.com/zhang-bo/p/7229084.html
Copyright © 2011-2022 走看看