Do not copy it. Even if you write it again, you can learn something: the original address.
When the project is handed over and the code is sensitive (the boss himself said, I do not agree with it), the code written by the old guys is too good (no comments) and there are many preliminary tasks, it is a waste of time and effort to read the code. The eyes are full of bloodshot in one day. I'm immune now. I 've put aside too many concerns. I'm very happy to read a piece of code. Haha (I am waiting to die later. I have a lot of tasks. I have 18 items ahead of the holiday and I don't have time for myself, but you can have a good sleep)
There are SOLR and SSH projects in the project to be handed over. The test team wants to print the SOLR and SSH logs separately for ease of searching. They also need to simulate spring writing and testing, so I checked the knowledge and configured it for them directly. But I used the configuration in two places first. Now I have time to study it. I will help them modify it later and complete the project.
<pre name="code" class="html">log4j.rootLogger=INFO, CONSOLE, A
Log4j. appender. console = org. apache. log4j. leleappenderlog4j. appender. console. layout = org. apache. log4j. patternlayoutlog4j. appender. console. layout. conversionpattern = [%-5 p] % d {hh: mm: SS} (% F: % L)-% m % nlog4j. appender. A = org. apache. log4j. dailyrollingfileappenderlog4j. appender. a. file = .. /webapps/r2k/logs/log.txt log4j. appender. a. layout = org. apache. log4j. patternlayoutlog4j. appender. a. layout. conversionpattern = [%-5 p] % d {hh: mm: SS} (% F: % L)-% m % nlog4j.logger.com. apabi = debug
Above:
1. log4j. rootlogger = info, console,
Here, rootlogger defines the log output level as info. And the output location as console, and a (which can be understood as two choices ). The output level can be divided into off <fatal <error <Waring <info <debug <all, where off is the lowest. When off is selected, no information is output, and info prints off, fatal, error, Waring, info, and other options can be understood. Console and a respectively find the following configuration information
2. log4j. appender. Console = org. Apache. log4j. leleappender
The types at the output end of the console are defined here. All options are as follows:
Org. Apache. log4j. leleappender (console ),
Org. Apache. log4j. fileappender (file ),
Org. Apache. log4j. dailyrollingfileappender (a log file is generated every day ),
Org. Apache. log4j. rollingfileappender (a new file is generated when the file size reaches the specified size)
Org. Apache. log4j. writerappender (send log information to any specified place in stream format)
3. log4j. appender. A. File = ../webapps/r2k/logs/log.txt
Bytes
4. log4j. appender. A. layout = org. Apache. log4j. patternlayout
The output file is displayed in the following format:
Org. Apache. log4j. htmllayout (in the form of HTML tables ),
Org. Apache. log4j. patternlayout (you can flexibly specify the layout mode ),
Org. Apache. log4j. simplelayout (including the log information level and information string ),
Org. Apache. log4j. ttcclayout (including the log generation time, thread, category, and so on)
5. log4j. appender. a. layout. conversionpattern = [r2k] [%-5 p] % d {hh: mm: SS} (% F: % L)-% m % N
<span style="font-family: Calibri;font-size:12px; line-height: 25.1875px;"> </span><span style="font-family: Calibri;font-size:12px; line-height: 25.1875px;">log4j.appender.stdout.layout.ConversionPattern= [QC] %p [%t] %C.%M(%L) | %m%n</span>
If you use the pattern layout, you must specify the specific format of the print information conversionpattern. The print parameters are as follows:
% M output the specified message in the code
% P output priority, namely debug, info, warn, error, fatal
% R the number of milliseconds it takes to output the log information from application startup to output
% C output category, usually the full name of the class
% T name of the thread that outputs the log event
% N output a carriage return line break. For Windows, the value is "RN", and for UNIX, the value is "N"
% D date or time of the log output time point. The default format is iso8601. You can also specify the format after it, for example, % d {yyyy Mmm dd hh: mm: SS, SSS}, output is similar to: October 18, 2002 22:10:28, 921
% L location of log event output, including category name, thread, and number of lines in the code.
[QC] is the beginning of log information. It can be any character, generally referred to as project.
Output Information
[Ts] Debug [main] abstractbeanfactory. getbean (189) | returning cached instance of Singleton bean 'myautoproxy'
For details, refer to the third part to define the formatting log information in the configuration file.
6. log4j.logger.com. Apabi = debug
The output Log Level of the class under the com. Apabi package in the specified project is defined as debug
7. log4j.logger.org. Apache. commons = Error log4j.logger.org. Apache. Struts = warn
These two statements are struts packages.
8. log4j.logger.org. springframework = debug
This is a spring package.
9. log4j.logger.org. hibernate. PS. preparedstatementcache = warn log4j.logger.org. hibernate = debug
Here are the hibernate packages.
10
- Log4j.logger.com. fuyou. log. Test2 = debug, test2log
- Log4j.logger.com. fuyou. log. test = debug, testlog
Different packages are output to different places.
4. Use of log4j
A) download the commongs-logging package from www.apache.org;
B) define protected final log logger = logfactory. getlog (this. getclass () in your class ());
C) logger.info (...) where the log output is needed (...), logger. error (...), logger. debug (...),.... note: before use, it is best to make a judgment if (logger. isdebugenabled () {logger. debug ("... ");} others are similar.
1) I need to make a research. If I don't deserve a place, which one should I select when the project comes?
2) COM. hibernat = debug is configured, while com.hibernate.de = info declares whether there is any order and whether it will be overwritten. See the source code.
Log4j configuration file Learning