In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-04-01 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
This article shares with you the content of the sample analysis of rootLogger in log4j. The editor thinks it is very practical, so share it with you as a reference and follow the editor to have a look.
Log4j's rootLogger and other tricks
Org.apache.log4j.Logger is used here.
Log4j.rootLogger=error, stdout log4j.appender.appenderName=org.apache.log4j.AsyncAppender log4j.appender.stdout=org.apache.log4j.ConsoleAppenderlog4j.appender.stdout.Target=System.outlog4j.appender.stdout.layout=org.apache.log4j.PatternLayoutlog4j.appender.stdout.layout.ConversionPattern=%d {ABSOLUTE}% 5p% c {1}:% L -% m%n#only time no date.outfile1 has date log4j.logger.com.ht=info Outfile1 log4j.appender.outfile1=org.apache.log4j.RollingFileAppenderlog4j.appender.outfile1.File=log/ht.loglog4j.appender.outfile1.MaxFileSize=100MBlog4j.appender.outfile1.MaxBackupIndex=50log4j.appender.outfile1.layout=org.apache.log4j.PatternLayoutlog4j.appender.outfile1.layout.ConversionPattern=%d {yyyy-MM-dd HH:mm:ss}% 5p% c {1}:% L -% m% n log4j.logger.com.ht.log=info Outfile2 log4j.appender.outfile2=org.apache.log4j.RollingFileAppenderlog4j.appender.outfile2.File=log/ht2.loglog4j.appender.outfile2.MaxFileSize=100MBlog4j.appender.outfile2.MaxBackupIndex=50log4j.appender.outfile2.layout=org.apache.log4j.PatternLayoutlog4j.appender.outfile2.layout.ConversionPattern=%d {yyyy-MM-dd HH:mm:ss}% 5p% c {1}:% L -% m% n
Then there are two classes, Test1 under the com.ht package and Test2 under the com.ht.log package. Print a sentence below each: logger.info ()
It is found through the experiment!
Test1 will be output to the console and ht.log
Test2 will be output to the console and to ht.log and ht2.log
Note that the level of rootLogger here is error, which shows that the level here does not work.
Does not work with the level setting of the package rootLogger that declares appender
In fact, the error here only works for packages that do not declare appender. If you remove the sentence log4j.logger.com.ht.log, Test1 does not have any output, unless logger.error will output to the console.
The second point: any package that declares appender must contain the output of rootLogger regardless of the declaration level. If outfile is also specified, there will be two copies of the log.
The third point: the classes under the com.ht.log package can match the settings of all parent directories.
How to set up the log to think clearly ah! Otherwise, if this sentence hits the file in the console, the log found out is not coherent when something goes wrong, and several files will be checked and checked.
Log4j.additivity.com.ht=false may not be written to rootLogger. Default is true
Log4j rootLogger configures the log4j.rootLogger=INFO,db syntax as log4j.rootLogger= [level], appenderName1, appenderName2, …
Level: is the priority of logging, divided into OFF, FATAL, ERROR, WARN, INFO, DEBUG, ALL, or levels that you define.
Log4j recommends using only four levels, and the priorities from highest to lowest are ERROR, WARN, INFO, and DEBUG.
With the levels defined here, you can control the switch to the corresponding level of log information in the application.
For example, if the INFO level is defined here, all DEBUG-level log information in the application will not be printed.
AppenderName: specifies where the log information is output. You can specify multiple output destinations at the same time.
For example:
Log4j.rootLogger=info,A1,B2,C3 is configured with three output places, and this name can be arbitrary (such as db above), but it must correspond to the name of the setting we will make later.
Thank you for reading! This is the end of this article on "sample Analysis of rootLogger in log4j". I hope the above content can be of some help to you, so that you can learn more knowledge. if you think the article is good, you can share it for more people to see!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.