标签:sage tar mes ati 依赖 java 实例 logger pom
原文链接:https://www.jianshu.com/p/eb4ac2571c94?tdsourcetag=s_pctim_aiomsg
<dependency> <groupId>log4j</groupId> <artifactId>log4j</artifactId> <version>1.2.12</version> </dependency>
### 设置### log4j.rootLogger = debug,stdout,D,E ### 输出信息到控制台 ### log4j.appender.stdout = org.apache.log4j.ConsoleAppender log4j.appender.stdout.Target = System.out log4j.appender.stdout.layout = org.apache.log4j.PatternLayout log4j.appender.stdout.layout.ConversionPattern = [%-5p] %d{yyyy-MM-dd HH:mm:ss,SSS} method:%l%n%m%n ### 输出DEBUG 级别以上的日志到日志文件 ### log4j.appender.D = org.apache.log4j.DailyRollingFileAppender log4j.appender.D.File = /home/duqi/logs/debug.log log4j.appender.D.Append = true log4j.appender.D.Threshold = DEBUG log4j.appender.D.layout = org.apache.log4j.PatternLayout log4j.appender.D.layout.ConversionPattern = %-d{yyyy-MM-dd HH:mm:ss} [ %t:%r ] - [ %p ] %m%n ### 输出ERROR 级别以上的日志到日志文件 ### log4j.appender.E = org.apache.log4j.DailyRollingFileAppender log4j.appender.E.File =/home/admin/logs/error.log log4j.appender.E.Append = true log4j.appender.E.Threshold = ERROR log4j.appender.E.layout = org.apache.log4j.PatternLayout log4j.appender.E.layout.ConversionPattern = %-d{yyyy-MM-dd HH:mm:ss} [ %t:%r ] - [ %p ] %m%n
如果日志文件没有设置路径的话,那么日志文件会输出到工程目录下。
import org.apache.log4j.*; public class Demo { private static Logger logger = Logger.getLogger(vincent_player_framt.class); public static void main(String[] args) throws Exception { // debug级别的信息 logger.debug("This is debug message."); // info级别的信息 logger.info("This is info message."); // error级别的信息 logger.error("This is error message."); } }
标签:sage tar mes ati 依赖 java 实例 logger pom
原文地址:https://www.cnblogs.com/lvchengda/p/12956834.html