log4j the log of the generated program.First you need a configuration file:log4j.propertiesLog4j.rootlogger = Debug, stdout, D, Elog4j.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% NLOG4J.APPENDER.D = Org.apache.log4j.dailyroll
dimension of the Num class name output (such as: "Org.apache.elathen.ClassName",%c{2} will output elathen. ClassName)
%d output log time in the format of%d{yyyy-mm-dd hh:mm:ss,sss}, you can specify a format such as%d{hh:mm:ss}
%l output Log event occurrence location, including class name, occurrence thread, number of lines in code
%n line break
%m output code to specify information, such as info ("message"), output message
%p output priority, that is, FATAL, ERROR, etc.
%r output the number of
flexibility to specify layout mode), Org.apache.log4j.SimpleLayout (contains the level and information string for log information), Org.apache.log4j.TTCCLayout (contains information about the time, thread, category, and so on) log4j formats the log information in print format similar to the printf function in C, and prints the following parameters:%m The message specified in the output code %p The output priority, which is Debug,info,warn,error
1. New Java Project Log4test2, New directory lib, the Log4j-1.2.9.jar package into the Lib directory3, right-click Project, choose Properties->java Build path->libraries->add JARs ..., select the Log4j-1.2.9.jar under Lib4. Create two new files in src directory log4j.properties and Log.txtThe Log4j.properties file is configured as follows:log4j.appender.stdout.layout.conversionpattern=%d%p [%c]-%m%nLog4j.ap
Add slf4j-api-1.6.1,slf4j-log4j12-1.6.1,log4j-1.2.15 three jar packages to the Lib folder to use the log4j log file. Specifically configured in the Log4j.properties file. Different configurations of the file can be modified to achieve different functions. For example Log4j.rootlogger=warn, stdout modified to Log4j.rootlogger=error, stdout. Only errors are displayed. Specific as followsDebug Debugging Inform
Configuring log4j monitoring and file mapping and related settings in Web. xml
Web. XML code
Content configuration and parsing of log4j.properties
# Debug,info,warn,error,fatal Log level
log_level=info
log4j.rootlogger=${log_level},console,file
# LOG4J encoding format, time format settings
Log4j.appender.console=org.apache.log4j.consoleappender
Log4j.append
To use log4j in your project, the general process is as follows:The 1.web.xml configuration file is configured to load in the log4j. As follows2. Use the log4j in the code to print the log.There are two ways to use it, one is an alias application and one is a package reference.Alias use is to configure the alias in the
Log4j are often used in the project, and generally include 4 steps:1. Write the log4j configuration file;2. Initialization of log4j;3. Obtain a logger instance;4. Call Logger.debug () and other logging.In order to control the log output of each package and class in detail, it is generally necessary to set a logger inst
LOG4J supports two configuration file formats, one is the Java property file (the key-value) and the other is the XML format file.
Here is a description of how to configure the Java properties file.First look at the configuration file: Log4j.properties
Log4j.rootcategory=debug,stdout,r
Log4j.appender.stdout=org.apache.log4j.consoleappenderLog4j.appender.stdout.la
LOG4J is the best log component on the Java platform, and log4j 2 upgrades a lot of APIs to make it more scalable. The use of words only need to be introduced directly on it.
Then configure the log4j configuration file, the configuration file online Balabala a lot of it.
Download three packages:Three packages are: Log4j API package, SLF4J API package, SLF4J to log4j adapter package.One important reason to choose to use SLF4J is to support the placeholder {} without frequently manipulating string objects.The implementation code is as follows:ImportOrg.slf4j.Logger;Importorg.slf4j.LoggerFactory; Public classtestslf4jlogging {Private FinalLogger Logger = Loggerfactory.getlogge
When using log4j to print the application log, a colleague asked me if the different level of the same logger log could be output to a different file? This one... I told him. Of course, in our production environment using log4j has always been all logger error above level log input to the error log file, convenient system monitoring.In fact, this is easy to achieve, we are to add 2 appender,appender in logg
When the jar package introduced in the project contains Log4j.xml or Log4j.properties, the configured log4j is overwritten, which invalidates the log4j of the configuration. To confirm whether it is overwritten, first check the path of the log4j profile read at the start of the project, you can find the service you con
Benefits of using logs:Log information can be saved for a long time.Logs can be saved to: network, file, databaseSets the level of the log.OFFFatal–system.exit (0); -JVM,error– error, module error.warn– WarningInfo-Programmer Debug Information-equivalent to System.err. And that's how we often output it.Debug-system.out. – In general, the frame is used out.OnSet Print level Up compatibilityLOG4J requires two files:1, Guide Package Log4j.jar2, log4j
When a method is configured in quartz, it is called sequentially two times, because it is loaded two times, just modify the configuration in Tomcat Server.xmlHostname= "www.xx.cn"AppBase=""Unpackwars= "true"Autodeploy= "true"> ContextPath=""DocBase= "Webapps/demo"reloadable= "true"/> ValveClassName= "Org.apache.catalina.valves.AccessLogValve"Directory= "Logs"prefix= "Localhost_access_log."suffix= ". txt"pattern= "%h%l%u%t quot;%rquot;%
First, log4j sub-environment configuration:
1. Add the following configuration to the Web. XML to host spring's helper to listen for file refreshes
2. The sub-environment is also easy, as Web. XML can use system environment variables. As below, in the development machine Tomcat boot parameters to configure the-denv=dev is done. Default Read
Log4j can support log output to files, databases, and even remote servers, this time to share how to output to MySQL.(1) the configuration of the log4j.properties is as follows: log4j.rootlogger=error,appender1,appender2 log4j.appender.appender1= Org.apache.log4j.ConsoleAppender Log4j.appender.appender1.layout=org.apache.log4j.patternlayout LOG4J.APPENDER.APPENDER1.LAYOUT.CONVERSIONPATTERN=%D{YYYY-MM-
Rootlogger parameter stdout also to change to a, the other used places of course also need to change. The key here is not the name, but the Appender type, such as the "consoleappender" Here, see it, output to the console. The next two lines are the format of the log, under normal circumstances you copy it.Two. configuration aspect: Put log4j bag and commons-logging bag (add together only two) put below cla
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.