Do the project is log4j output formatting parameters get bored, simply the relevant part of the API is roughly translated, the original see http://logging.apache.org/log4j/docs/api/org/apache/log4j/PatternLayout.html
Parameters
Description
Example
% C
Lists the full name of a logger namespace. If {
Example of parameters in the
Log4j is used in spring, but because the project needs to use the Task Scheduler, so add quartz, but quartz need sfl4j-log4j and SFL4J-API
However, if you use sfl4j-log4j and log4j, there will be conflicts ... Error occurs at startup
Then you need to convert the version of quartz ...
Project original Lib Quartz is 1
steps:
Create a new Java project and import the log4j jar package;
Create the Log4j.properties profile and set it in the SRC directory;1 # Set the global output level2Log4j.rootlogger=Error,stdout,file3 4 # Output logs above the error level to the console5log4j.appender.stdout=Org.apache.log4j.ConsoleAppender6log4j.appender.stdout.target=System.out7log4j.appender.stdout.layout=Org.apache.log4j.PatternLayout8Log4j.appender.stdout.layout.conversio
The project uses log4j print content to transfer to flume1, Flume endThe agent configuration for Flume is as follows:
12345678910111213141516
a1.sources=s1a1.sinks=k1a1.channels=c1a1.sources.s1.channels=c1a1.sinks.k1.channel=c1a1.sources.s1.type=avroa1.sources.s1.bind=vm1a1.sources.s1.port=41414 a1.sinks.k1.type=loggera1.channels.c1.type=memorya1.channels.c1.capacity=1000a1.channels.c1.transactionCapacity=100
Start the
Log4j defines the Log Level and log4j Log Level of a class.
After a scheduled task is introduced into the project, when I delete an existing scheduled task
[Org. springframework. scheduling. quartz. localperformancejobstore] ClusterManager: detected 1 failed or restarted instances.[Org. springframework. scheduling. quartz. localperformancejobstore] ClusterManager: Scanning for instance "***"'s failed in
Link: http://blog.csdn.net/guoquanyou/article/details/5689652
Do the project is log4j output format parameters annoying, simply put the relevant parts of the API roughly translated, the original see http://logging.apache.org/log4j/docs/api/org/apache/log4j/PatternLayout.html
Parameters
Description
Example
%c
Lists the full name
program to achieve their own:)LOG4J2 is an upgraded version of log4j, log4j2 in addition to meet the above needs, heard the performance is also better, the old project log4j upgrade to LOG4J2 cost is also low.First, log4j configurationOfficial Document: Http://logging.apache.org/log4j/1.2/apidocs1.
to do log4j loggingIn addition to the above benefits, I think there is a caveat that, in order to use SLF4J, you need not only to include the SLF4J API jar package, such as Slf4j-api-1.6.1.jar, but also the relevant jar package, depending on the Log class library you use in the background. If you want to use SLF4J with log4j, simple Logging facade for Java, you need to include the following jar package in
To be perfected:(1). Here is an introduction to log4j more detailed blog, a cursory look at the next time to look deeper, write a more in-depth introduction, the first link recorded here:Log4j Detailed IntroductionThe log about log4j has been confused. Here is a summary summary:(2) log4j has a lot of bugs, such as deadlock. Now there are logback and log4j2. I'll
is {} ' I am {} years old. ', name, age);
}
2. Because the interior has been optimized, the authors believe that SLF4J's logger need not be defined as static.
3. Can set the cache after the bulk write log files (but if the server reboots, may lose records not written to disk)
4.MDC, with filter, the current user name and other business information into the MDC, in the log format definition can use the variable.
5.JMS Appender for alarms, DB appender for business logs, etc.
Production en
The following is written in the official log4j API, which is sufficient to explain the difference between logger and category...
public class Category
Extends java. Lang. Object
Implements appenderattachable
This class has been deprecated andReplaced byLogger Subclass. ItWill be kept around to preserve backward compatibility until mid2003.
LoggerIs a subclass of category, I. e. It extendsCategory. In other words, a loggerIsA c
Do the project is log4j output format parameters annoying, simply put the relevant parts of the API roughly translated, the original see http://logging.apache.org/log4j/docs/api/org/apache/log4j/PatternLayout.htmlParameter Description Example%c lists the full name of the logger namespace, and if the addition of the {Suppose the current logger namespace is "A.B.C"
log4j Configuration Sample
#定义根日志级别和输出端 (two outputs defined) Log4j.rootlogger=error,console,orclight #定义第一个输出端, output to console log4j.appender.console=
Org.apache.log4j.ConsoleAppender Log4j.appender.console.layout=org.apache.log4j.patternlayout log4j.appender.console.layout.conversionpattern=%d [%t]%-5p%c (%l)-%m%n #定时第二个输出端, output to a file with a maximum space of 1000KB, Automatically back up after 1000KB, generate new files Log4j.appender.or
Log4j configuration file is used to set the recorder level, storage device, and layout. It can be connected to key = value format settings or XML format settings. Through configuration, you can create a log4j runtime environment.
1. Configuration FileThe basic format of the log4j configuration file is as follows:# Configure the root Logger
Received a demand, through the log4j time print log, requirements described as follows: the need to be able to print the log regularly, the interval can be matched. When it comes to timing, first think of the Dailyrollingfileappender class, various timing, according to Datepattern, this can refer to class SimpleDateFormat class, common some of the regular settings are as follows:
[HTML]View Plain copy print? '.' YYYY-MM: Monthly '. ' YYYY-WW: Weekly '
The powerful function of log4j is unquestionable, but in practical application it is unavoidable to have a function to output independent log files, how to separate the required content from the original log, and form a separate log file. In fact, as long as the existing log4j based on a little configuration can easily achieve this function.
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.