) throws Servletexception, IOException {doget (Request,
Response); }
}
The next step is to run, to see the results:
Output results:
V. Use LOG4J in spring
Here to implement a Web project using spring to use the log4j
(1) Connect the above project and then import the spring package
(2) Web.xml increase
The whole contents are as follows:
Log4jinitservlet.java here i
Disadvantages and advantages:Logs are an important part of software development. A well-written log code provides fast debugging, easy maintenance, and structured storage of application run-time information.Logging does have its drawbacks, too. It can slow down the application. If too detailed, it may cause rolling blindness. To mitigate these effects, the log4j is designed to be reliable, fast and scalable.Since records are rarely the primary focus
/index.jsp Download and install on your computer
Java Information Services: LOG4J's JMS-compatible features will require two JMS and Jndi (Java naming and directory interfaces) that can be downloaded from the HTTP://JAVA.SUN.COM/PRODUCTS/JMS installation
XML Parser: Requires a JAXP-compatible XML parser to use log4j. Make sure you have Xerces.jar installed on your machine and can download and install from http://xerces.apache.org/xerces-j/inst
; click Use as Source Folder.Now it's time to write a Java class and run it, with an example like this:1 PackageOrg.warnier.zhang.demo;2 3 ImportOrg.apache.log4j.Logger;4 5 Public classTest {6 /**7 * acquisition of recorders;8 */9 StaticLogger Logger = Logger.getlogger (Test.class);Ten One Public Static voidMain (string[] args) { ALogger.debug ("Debug > Hello world!"); -Logger.info ("Info > Hello world!"); - } the -}Here, the Apache
The benefits of Log4j 2 will not be discussed with everyone. If you search for 2, it means you have some knowledge about it and want to use it, so you can get started directly here.
1. Download log4j 2 from the official website.To import the jar package, you only need to import the following two jar packages (xx is a messy version ):
Log4j-core-xx.jar
Continue with the example in the log4j introductory tutorial (i), where the contents of Log4j.properties are three important components of log4j- loggers, Appenders, Layouts, the work of the three components together , enabling developers to record information based on information categories and levels, and to be able to control how records are logged in the way
The previous chapter describes the core components of log4j. This chapter describes how to use configuration files to configure these core components. Configuration log4j involves assigning levels, defining an append program, and specifying the layout object in the configuration file.The Log4j.properties file is a key-value pair that holds the Log4j configuration
We've seen how to create a profile earlier. This tutorial will explain how to generate debug information and log in a simple text file.Here is a simple configuration file created in our example. Repeat here:
Download the latest log4j library: http://logging.apache.org/log4j/2.x/download.html
The root logger level is defined as debug and the connectio
The log is an integral part of the application software, and the Apache Open source project log4j is a powerful log component that provides easy logging. On the Apache website: jakarta.apache.org/log4j can download the latest version of the log4j package for free.An example of getting Started
1. Create a new Java project, import package
The log is an integral part of the application software, and the Apache Open source project log4j is a powerful log component that provides easy logging. On the Apache website: jakarta.apache.org/log4j can download the latest version of the log4j package for free. An example of getting Started
1. Create a new Java project, import package
The log is an integral part of the application software, and the Apache Open source project log4j is a powerful log component that provides easy logging. On the Apache website: jakarta.apache.org/log4j can download the latest version of the log4j package for free. An example of getting Started
1. Create a new Java project, import package
.*;ImportJava.util.*; Public classlog4jexample{/*Get Actual class name to being printed on*/ StaticLogger log =Logger.getlogger (log4jexample.class. GetName ()); Public Static voidMain (string[] args)throwsioexception,sqlexception{Log.debug ("Debug"); Log.info ("Info"); }}Compile and run:Here are the steps to compile and run the above program. Ensure that path and classpath are set appropriately before compiling and executing.All libraries should be available in path classpath as well as log4j
'. ' Yyyy-mm-dd
This is the default value, which scrolls every day at midnight
'. ' Yyyy-mm-dd-a
Scroll every day at midnight and noon
'. ' Yyyy-mm-dd-hh
Scroll in every one hours
'. ' Yyyy-mm-dd-hh-mm
Rolling in every Minute
'. ' Yyyy-ww
The first day of the week depending on the regional setting is scrolled
The following is a sample configuration file that log4j.properties generate l
in the example above.=/usr/home/= WARN, file# Define the FILE appenderlog4j.appender.FILE= Org.apache.log4j.FileAppenderlog4j.appender.FILE.File=${log}/ for FILE Appenderlog4j.appender.FILE.layout= Org.apache.og4j.PatternLayoutlog4j.appender.FILE.layout.conversionPattern=%m%nNow, use the following program:Importorg.apache.log4j.*; Public classLogclass {Private StaticOrg.apache.log4j.Logger log =Logger. GetLogger (Logclass.class); Public Static voidMain (string[] args) {Log.trace ("Trace mess
to the title of the HTML file. The default value is log4j log information
htmllayout Example:Here is a simple configuration file for Htmllayout:=/usr/home/= DEBUG, file# Define the FILE appenderlog4j.appender.FILE= Org.apache.log4j.FileAppenderlog4j.appender.FILE.File=${log}/ for FILE Appenderlog4j.appender.FILE.layout=Org.apache.log4j.HTMLLayoutlog4j.appender.FILE.layout.Title= HTML Layout Examplelog4j.appender.FILE.layout.LocationInfo=t
An example of getting Started
1. Create a new Java project, import package Log4j-1.2.17.jar, the entire project final catalogue is as follows2, SRC peers to create and set log4j.properties
### Settings ###Log4j.rootlogger = debug,stdout,d,e output information to control lift
Log4j.appender.stdout = Org.apache.log4j.ConsoleAppenderLog4j.appender.stdout.Target = System.outLog4j.appender.stdout.layout = Org.apache.log4j.PatternLayoutLog4j.appender.stdout
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.