多个日志文件如何在其中添加通用框架日志

时间:2019-06-27 13:32:22

标签: java log4j

在一个项目中,有几个与main相关的类,并希望为每个main类创建不同的日志文件。

下面尝试使用log4j创建两个不同的日志文件,但希望在日志文件中也包含与spring相关的日志记录。

Spring日志记录位于根记录程序文件MyApp.log中。如何在OrdersLoad.log和EmployeesLoad.log中记录这些记录

请对此提供帮助。

Project1

MainClass1 ------ MainClass1,Subclass11,Subclass12的日志文件1

MainClass2 ------ MainClass2,Subclass21,Subclas22的日志文件2

这是log4j属性

# Root logger option
log4j.rootLogger=DEBUG, stdout, file

# Redirect log messages to console
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=%d{yyyy-MM-dd HH:mm:ss} %-5p %c{1}:%L - %m%n


# logger level for spring framework
#log4j.logger.org.springframework=INFO
#log4j.logger.org.springframework.batch=INFO
#log4j.category.org.springframework.integration.file=TRACE
log4j.logger.com....myapp=INFO
log4j.category.org.springframework.jdbc.core.JdbcTemplate=DEBUG
log4j.category.com.jcraft.jsch=INFO


# Redirect log messages to a log file, support file rolling.
log4j.appender.file=org.apache.log4j.RollingFileAppender
log4j.appender.file.File=C:\\Test\\MyApp.log
log4j.appender.file.MaxFileSize=5MB
log4j.appender.file.MaxBackupIndex=10
log4j.appender.file.layout=org.apache.log4j.PatternLayout
log4j.appender.file.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss} %-5p %c{1}:%L - %m%n



# Direct log messages for orders load to a orders log file
log4j.logger.com......File1=DEBUG, orders
log4j.additivity.com......File1=false
log4j.logger.com......File2=DEBUG, orders
log4j.additivity.com......File2=false
log4j.logger.com......File3=DEBUG, orders
log4j.additivity.com......File3=false
log4j.appender.orders=org.apache.log4j.RollingFileAppender 
log4j.appender.orders.File=C:\\Test\\OrdersLoad.log
log4j.appender.orders.MaxFileSize=10000KB
log4j.appender.orders.MaxBackupIndex=10
log4j.appender.orders.layout=org.apache.log4j.PatternLayout
log4j.appender.orders.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss} [%t] %-5p:: %m%n



# Direct log messages for employees load to a employees group log file
log4j.logger.com......File4=DEBUG, emp
log4j.additivity.com......File4=false
log4j.logger.com......File5=DEBUG, emp
log4j.additivity.com......File5=false
log4j.logger.com......File6=DEBUG, emp
log4j.additivity.com......File6=false
log4j.appender.emp=org.apache.log4j.RollingFileAppender
log4j.appender.emp.File=C:\\Test\\EmployeesLoad.log
log4j.appender.emp.MaxFileSize=10000KB
log4j.appender.emp.MaxBackupIndex=10
log4j.appender.emp.layout=org.apache.log4j.PatternLayout
log4j.appender.emp.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss} [%t] %-5p:: %m%n

0 个答案:

没有答案