On a certain day, the customer responded to the system error, and he shared the log. Open the log file and watch it, "" How can you find the information I want in such a big file, and the information thrown in the package, the whole weeds. " That is not allowed to turn over the document, see if there is a solution, the emperor does not have a person, and finally find the file method that can be classified and output logs.
Hey, the following is a way to achieve.
1. Open log4j.properties file
2. Configure different Logger, Level, Appender, such as depending on the Package class.
# 地局 日 级
Log4j.rootlogger = error
# org. * Log Level and Output Appender
Log4j.logger.org = Error, A1
# com.java.test's log level and output Appender
Log4j.logger.com.java.test = Debug, A2
# Net.sf.hibernate log level and output Appender
Log4j.logger.net.sf.hibernate = Error, A3
3. Configure Appender
Log4j.Appender.a1 = org.apache.log4j.rollingfileappender
Log4j.Appender.a1.file = C: /LOGS/TEST-A1.LOG
Log4j.Appender.a1.maxfilesize = 500kb
Log4j.Appender.a1.maxbackupindex = 50
Log4j.Appender.a1.append = TRUE
Log4j.Appender.a1.Layout = Org.apache.log4j.patternlayout
Log4j.Appender.a1.Layout.conversionPattern =% d {ISO8601} - [% P] [% C {1}] -% M% N
Log4j.Appender.a2 = org.apache.log4j.rollingfileappender
Log4j.Appender.a2.file = c: /logs/test-a1.log
Log4j.Appender.a2.maxfilesize = 500kb
Log4j.Appender.a2.maxbackupindex = 50
Log4j.Appender.a2.append = TRUE
Log4j.Appender.a2.Layout = Org.apache.log4j.patternlayout
Log4j.Appender.a2.Layout.conversionPattern =% d {ISO8601} - [% P] [% C {1}] -% M% N
Log4j.Appender.a3 = org.apache.log4j.rollingfileappender
Log4j.Appender.a3.file = c: /logs/test-a3.log
Log4j.Appender.a3.maxfilesize = 500kb
Log4j.Appender.a3.maxbackupindex = 50
Log4j.Appender.a3.append = TRUE
Log4j.Appender.a3.Layout = org.apache.log4j.patternlayout
Log4j.Appender.a3.Layout.conversionPattern =% d {ISO8601} - [% P] [% c {1}] -% M% N
Don't try it, I am full!