ThinkChat2.0新版上线,更智能更精彩,支持会话、画图、阅读、搜索等,送10W Token,即刻开启你的AI之旅 广告
## 1. pom ~~~ <properties> <slf4j.version>1.7.7</slf4j.version> <log4j.version>1.2.17</log4j.version> </properties> <dependency> <groupId>log4j</groupId> <artifactId>log4j</artifactId> <version>${log4j.version}</version> </dependency> <dependency> <groupId>org.slf4j</groupId> <artifactId>slf4j-api</artifactId> <version>${slf4j.version}</version> </dependency> <dependency> <groupId>org.slf4j</groupId> <artifactId>slf4j-log4j12</artifactId> <version>${slf4j.version}</version> </dependency> <dependency> <groupId>commons-logging</groupId> <artifactId>commons-logging</artifactId> <version>1.1.3</version> </dependency> ~~~ ## 2. properties log4j.properties ~~~ 下面定义日志输出级别是 INFO,并且配置了2个输出目的地,一个是A3,一个是console log4j.rootLogger = INFO,A3,CONSOLE //日志最低的输出级别 log4j.appender.A3.Threshold=INFO log4j.appender.A3.encoding=UTF-8 //每天产生一个文件DailyRollingFileAppender log4j.appender.A3 = org.apache.log4j.DailyRollingFileAppender //file 属性 指定产生日志文件的保存位置及文件名,这里是windows下的配置 // c:/logtest/logtest.log, //公司项目在linux下的配置是/app/weblogic/applications/logs/sxvip_logs log4j.appender.A3.File=c:/logtest/logtest.log //当有日志时立即输出,默认是true log4j.appender.A3.ImmediateFlush=true log4j.appender.A3.DatePattern='_'yyyy-MM-dd //日志布局方式 log4j.appender.A3.layout=org.apache.log4j.PatternLayout //日志文件中日志的格式 log4j.appender.A3.layout.ConversionPattern=%-d{yyyy/MM/dd HH:mm:ss} OSS %-5p [%c] - %m%n //这里使用org.apache.log4j.ConsoleAppender指定要把日志输出到控制台 log4j.appender.CONSOLE=org.apache.log4j.ConsoleAppender log4j.appender.Threshold=INFO //输出目标是 控制台 log4j.appender.CONSOLE.Target=System.out log4j.appender.CONSOLE.layout=org.apache.log4j.PatternLayout log4j.appender.CONSOLE.layout.ConversionPattern=%-d{yyyy/MM/dd HH:mm:ss} OSS %-5p [%c] - %m%n ~~~ ## 3. 构建log对象 ~~~ private static final Logger log = LoggerFactory.getLogger(HelloWorld.class); log.info("我们正在测试。。。。。"); ~~~