项目是有nutz项目脚手架搭建的,集成log4j 怎么把这些信息保存成文件 存储到tomcat呢?
怎样把控制台输出的信息记录在tomcat的日志呢?
16 回复
给你我的log4j.properties。放到classpath就行
#日志级别有:OFF、FATAL、ERROR、WARN、INFO、DEBUG、TRACE、ALL
log4j.rootLogger=ALL,Console,RollingFile
#修改第三方日志级别,开启想看到的日志
log4j.logger.org.springframework.jdbc.datasource.init=INFO
log4j.logger.org.nutz.dao.impl.sql.run.NutDaoExecutor=DEBUG
#修改第三方类库的日志级别,避免看到太多不关心的日志
log4j.logger.org.apache.shiro=ERROR
log4j.logger.org.springframework=ERROR
log4j.logger.net.bull.javamelody=ERROR
log4j.logger.org.mybatis=ERROR
log4j.logger.org.apache.ibatis=ERROR
log4j.logger.com.alibaba.druid=ERROR
log4j.logger.net.sf.ehcache=ERROR
log4j.logger.org.quartz=ERROR
log4j.logger.org.apache.hadoop=ERROR
log4j.logger.org.apache.zookeeper=ERROR
log4j.logger.org.nutz=ERROR
log4j.logger.org.apache.http=ERROR
#控制台日志
log4j.appender.Console=org.apache.log4j.ConsoleAppender
log4j.appender.Console.Target=System.out
log4j.appender.Console.Threshold=DEBUG
log4j.appender.Console.layout=org.apache.log4j.PatternLayout
log4j.appender.Console.layout.ConversionPattern=[%p][%d{yyyy-MM-dd HH\:mm\:ss,SSS}][%l]%m%n
#每小时生成一个日志文件
log4j.appender.RollingFile=org.apache.log4j.DailyRollingFileAppender
log4j.appender.RollingFile.Threshold=ALL
log4j.appender.RollingFile.file=../logs/log
log4j.appender.RollingFile.DatePattern='_'yyyyMMdd_HH'.txt'
log4j.appender.RollingFile.layout=org.apache.log4j.PatternLayout
log4j.appender.RollingFile.layout.ConversionPattern=[%p][%d{yyyy-MM-dd HH\:mm\:ss,SSS}][%l]%m%n
@qq_16dd5808 目前 我的log4j是这样配置 的 没有spring 没有mybatis
log4j.rootLogger=debug, BLUEJAY
log4j.category.org.nutz=debug, BLUEJAY
log4j.additivity.org.nutz=false
#Appenders ...
log4j.appender.BLUEJAY=org.apache.log4j.ConsoleAppender
log4j.appender.BLUEJAY.layout=org.apache.log4j.PatternLayout
log4j.appender.BLUEJAY.layout.ConversionPattern=%d [%t] %-5p %c - %m%n
改怎么改写呢
@qq_16dd5808 那现在改成酱紫 没问题吧
#日志级别有:OFF、FATAL、ERROR、WARN、INFO、DEBUG、TRACE、ALL
log4j.rootLogger=ALL,Console,RollingFile
#修改第三方日志级别,开启想看到的日志
log4j.logger.org.springframework.jdbc.datasource.init=INFO
log4j.logger.org.nutz.dao.impl.sql.run.NutDaoExecutor=DEBUG
#修改第三方类库的日志级别,避免看到太多不关心的日志
log4j.logger.org.apache.shiro=ERROR
log4j.logger.org.springframework=ERROR
log4j.logger.net.bull.javamelody=ERROR
log4j.logger.org.mybatis=ERROR
log4j.logger.org.apache.ibatis=ERROR
log4j.logger.com.alibaba.druid=ERROR
log4j.logger.net.sf.ehcache=ERROR
log4j.logger.org.quartz=ERROR
log4j.logger.org.apache.hadoop=ERROR
log4j.logger.org.apache.zookeeper=ERROR
log4j.logger.org.nutz=ERROR
log4j.logger.org.apache.http=ERROR
#控制台日志
log4j.appender.Console=org.apache.log4j.ConsoleAppender
log4j.appender.Console.Target=System.out
log4j.appender.Console.Threshold=DEBUG
log4j.appender.Console.layout=org.apache.log4j.PatternLayout
log4j.appender.Console.layout.ConversionPattern=[%p][%d{yyyy-MM-dd HH\:mm\:ss,SSS}][%l]%m%n
#每小时生成一个日志文件
log4j.appender.RollingFile=org.apache.log4j.DailyRollingFileAppender
log4j.appender.RollingFile.Threshold=ALL
log4j.appender.RollingFile.file=../logs/log
log4j.appender.RollingFile.DatePattern='_'yyyyMMdd_HH'.txt'
log4j.appender.RollingFile.layout=org.apache.log4j.PatternLayout
log4j.appender.RollingFile.layout.ConversionPattern=[%p][%d{yyyy-MM-dd HH\:mm\:ss,SSS}][%l]%m%n
@qq_16dd5808
log4j.rootLogger=debug, BLUEJAY
log4j.category.org.nutz=debug, BLUEJAY
log4j.additivity.org.nutz=false
#Appenders ...
log4j.appender.BLUEJAY=org.apache.log4j.ConsoleAppender
log4j.appender.BLUEJAY.layout=org.apache.log4j.PatternLayout
log4j.appender.BLUEJAY.layout.ConversionPattern=%d [%t] %-5p %c - %m%n
#日志级别有:OFF、FATAL、ERROR、WARN、INFO、DEBUG、TRACE、ALL
log4j.rootLogger=ALL,Console,RollingFile
#修改第三方日志级别,开启想看到的日志
log4j.logger.org.springframework.jdbc.datasource.init=INFO
log4j.logger.org.nutz.dao.impl.sql.run.NutDaoExecutor=DEBUG
#修改第三方类库的日志级别,避免看到太多不关心的日志
log4j.logger.org.apache.shiro=ERROR
log4j.logger.org.springframework=ERROR
log4j.logger.net.bull.javamelody=ERROR
log4j.logger.org.mybatis=ERROR
log4j.logger.org.apache.ibatis=ERROR
log4j.logger.com.alibaba.druid=ERROR
log4j.logger.net.sf.ehcache=ERROR
log4j.logger.org.quartz=ERROR
log4j.logger.org.apache.hadoop=ERROR
log4j.logger.org.apache.zookeeper=ERROR
log4j.logger.org.nutz=ERROR
log4j.logger.org.apache.http=ERROR
#控制台日志
log4j.appender.Console=org.apache.log4j.ConsoleAppender
log4j.appender.Console.Target=System.out
log4j.appender.Console.Threshold=DEBUG
log4j.appender.Console.layout=org.apache.log4j.PatternLayout
log4j.appender.Console.layout.ConversionPattern=[%p][%d{yyyy-MM-dd HH\:mm\:ss,SSS}][%l]%m%n
#每小时生成一个日志文件
log4j.appender.RollingFile=org.apache.log4j.DailyRollingFileAppender
log4j.appender.RollingFile.Threshold=ALL
log4j.appender.RollingFile.file=../logs/log
log4j.appender.RollingFile.DatePattern='_'yyyyMMdd_HH'.txt'
log4j.appender.RollingFile.layout=org.apache.log4j.PatternLayout
log4j.appender.RollingFile.layout.ConversionPattern=[%p][%d{yyyy-MM-dd HH\:mm\:ss,SSS}][%l]%m%n
@qq_16dd5808 log4j 最后 我这样写 你看看 有问题吗
#日志级别有:OFF、FATAL、ERROR、WARN、INFO、DEBUG、TRACE、ALL
log4j.rootLogger=ALL,Console,RollingFile,debug, BLUEJAY
log4j.category.org.nutz=debug, BLUEJAY
log4j.additivity.org.nutz=false
#Appenders ...
log4j.appender.BLUEJAY=org.apache.log4j.ConsoleAppender
log4j.appender.BLUEJAY.layout=org.apache.log4j.PatternLayout
log4j.appender.BLUEJAY.layout.ConversionPattern=%d [%t] %-5p %c - %m%n
#控制台日志
log4j.appender.Console=org.apache.log4j.ConsoleAppender
log4j.appender.Console.Target=System.out
log4j.appender.Console.Threshold=DEBUG
log4j.appender.Console.layout=org.apache.log4j.PatternLayout
log4j.appender.Console.layout.ConversionPattern=[%p][%d{yyyy-MM-dd HH\:mm\:ss,SSS}][%l]%m%n
#每小时生成一个日志文件
log4j.appender.RollingFile=org.apache.log4j.DailyRollingFileAppender
log4j.appender.RollingFile.Threshold=ALL
log4j.appender.RollingFile.file=../logs/log
log4j.appender.RollingFile.DatePattern='_'yyyyMMdd_HH'.txt'
log4j.appender.RollingFile.layout=org.apache.log4j.PatternLayout
log4j.appender.RollingFile.layout.ConversionPattern=[%p][%d{yyyy-MM-dd HH\:mm\:ss,SSS}][%l]%m%n
@wendal 输出日志才这么点。。。为什么不是全部的Console @qq_16dd5808
root@NuoShang:/usr/local/tomcat/logs# cat log
[INFO][2016-09-18 15:17:06,141][nuoshang.bluejay.modules.controllers.HomeModule.index(HomeModule.java:30)]HomeModule#index
[INFO][2016-09-18 15:26:37,532][nuoshang.bluejay.modules.controllers.HomeModule.index(HomeModule.java:30)]HomeModule#index
[DEBUG][2016-09-18 15:26:37,532][nuoshang.bluejay.modules.controllers.UserModule.login(UserModule.java:68)]Input params - name:
12312312312
[DEBUG][2016-09-18 15:26:37,535][nuoshang.bluejay.modules.controllers.UserModule.login(UserModule.java:69)]Input params - password:
123123
root@NuoShang:/usr/local/tomcat/logs#
#日志级别有:OFF、FATAL、ERROR、WARN、INFO、DEBUG、TRACE、ALL
log4j.rootLogger=ALL,Console,debug,BLUEJAY,RollingFile
log4j.category.org.nutz=debug, BLUEJAY
log4j.additivity.org.nutz=false
#Appenders ...
log4j.appender.BLUEJAY=org.apache.log4j.ConsoleAppender
log4j.appender.BLUEJAY.file=../logs/BLUEJAY_log
log4j.appender.BLUEJAY.layout=org.apache.log4j.PatternLayout
log4j.appender.BLUEJAY.layout.ConversionPattern=%d [%t] %-5p %c - %m%n
#控制台日志
log4j.appender.Console=org.apache.log4j.ConsoleAppender
log4j.appender.Console.Target=System.out
log4j.appender.Console.Threshold=DEBUG
log4j.appender.Console.layout=org.apache.log4j.PatternLayout
log4j.appender.Console.layout.ConversionPattern=[%p][%d{yyyy-MM-dd HH\:mm\:ss,SSS}][%l]%m%n
#每小时生成一个日志文件
log4j.appender.RollingFile=org.apache.log4j.DailyRollingFileAppender
log4j.appender.RollingFile.Threshold=ALL
log4j.appender.RollingFile.file=../logs/log
log4j.appender.RollingFile.DatePattern='_'yyyyMMdd_HH'.txt'
log4j.appender.RollingFile.layout=org.apache.log4j.PatternLayout
log4j.appender.RollingFile.layout.ConversionPattern=[%p][%d{yyyy-MM-dd HH\:mm\:ss,SSS}][%l]%m%n
你的配置文件好复杂.
log4j.rootLogger=debug,Console,RollingFile
log4j.appender.Console=org.apache.log4j.ConsoleAppender
log4j.appender.Console.layout=org.apache.log4j.PatternLayout
log4j.appender.Console.layout.ConversionPattern=[%-5p] %d{HH:mm:ss.SSS} %l - %m%n
log4j.appender.RollingFile=org.apache.log4j.DailyRollingFileAppender
log4j.appender.RollingFile.file=/var/log/abc
log4j.appender.RollingFile.layout=org.apache.log4j.PatternLayout
log4j.appender.RollingFile.layout.ConversionPattern=[%-5p] %d{HH:mm:ss.SSS} %l - %m%n
添加回复
请先登陆