# [This configuration is automatically generated after a large number of increases] # You can set the level: Debug> info> Error # Debug: Display debug, info, and Error # info: display info, Error # error: Only Error # log4j. rootlogger = debug, appender1 # log4j. rootlogger = info, appender1 ################### you can uncomment log4j. rootlogger = debug, appender1 # output to the file (the append method is used by default) # append indicates whether to write log4j again in the existing log during restart. appender. appender1 = org. apache. log4j. rollingfileappenderlog4j. appender. appender1.append = false # Set the file output path # [1] Text File log4j. appender. appen Der1.file = l:/log. log # Set the file output style [custom] log4j. appender. appender1.layout = org. apache. log4j. patternlayout # custom output format log4j. appender. appender1.layout. conversionpattern = [% d {YY/MM/dd hh: mm: SS: SSS}] [% C-% m] % m % N # %-d {yyyy-mm-dd hh: mm: SS} [% t: % R]-[% P] % m % N #7 define the maximum length of the A2 output file log4j. appender. appender1.maxfilesize = 2kb #8 defines the number of A2 backup files log4j. appender. appender1.maxbackupindex = 2 # [set how long to update to generate a file] # You can set the level: Debug> info> erro R # Debug: displays debug, info, and Error # info: displays info and Error # error: Only Error # log4j. rootlogger = debug, appender1 # log4j. rootlogger = info, appender1 #################### uncomment # log4j. rootlogger = debug, appender1 # output to a file (append mode is used by default) # append indicates whether to re-write logs to existing logs during restart # log4j. appender. appender1 = org. apache. log4j. dailyrollingfileappender # log4j. appender. appender1.append = false ### set the file output path ## [1] Text File # log4j. appender. appender1.file = l:/log. log # Set the file output sample Type [custom] # log4j. appender. appender1.layout = org. apache. log4j. patternlayout # custom output format # log4j. appender. appender1.layout. conversionpattern = [% d {YY/MM/dd hh: mm: SS: SSS}] [% C-% m] % m % N # %-d {yyyy-mm-dd hh: mm: SS} [% t: % R]-[% P] % m % N # define how long the file will be generated # log4j. appender. appender1.datepattern = '_' yyyy-mm-dd-hh-mm '. log' # [text format] # You can set the level: Debug> info> Error # Debug: Display debug, info, and Error # info: Display info and Error # error: only Error # log4j. rootlog GER = debug, appender1 # log4j. rootlogger = info, appender1 #################### uncomment # log4j. rootlogger = debug, appender1 ### output to a file (the append method is used by default) # append indicates whether to re-write data to the existing log during restart # log4j. appender. appender1 = org. apache. log4j. fileappender # log4j. appender. appender1.append = true ### set the file output path ## [1] Text File # log4j. appender. appender1.file = C:/log4jdemo02. log # Set the file output style # log4j. appender. appender1.layout = org. apache. log4j. ttcclayout # [HTML format] # It can be set Level: Debug> info> Error # Debug: displays debug, info, and Error # info: displays info and Error # error: Only Error # log4j. rootlogger = debug, appender1 # log4j. rootlogger = info, appender1 #################### uncomment # log4j. rootlogger = debug, appender1 # output to a file (append mode is used by default) # append indicates whether to re-write logs to existing logs during restart # log4j. appender. appender1 = org. apache. log4j. fileappender # log4j. appender. appender1.append = true ## set the file output path ## [2] HTML file # log4j. appender. appender1.file = C:/log4jdemo0 2. HTML ## set the file output style # log4j. appender. appender1.layout = org. apache. log4j. htmllayout # [Remarks] # Org. apache. log4j. htmllayout (layout in HTML form), # Org. apache. log4j. patternlayout (you can flexibly specify the layout mode), # Org. apache. log4j. simplelayout (the level that contains the log information and the information string), # Org. apache. log4j. ttcclayout (including the log generation time, thread, category, and other information) # % m the message specified in the output Code # % P output priority, that is, debug, info, warn, error, fatal # % R the number of milliseconds it takes to output the log information from application startup to output # % C the category of the output, it is usually the full name of the class where it is located # % t name of the thread that outputs the log event # % N output a carriage return line break, Windows: "/R/N", Unix: "/N" # % d date or time of the log output time point. The default format is iso8601, you can also specify a format later, for example, % d {YYY Mmm dd hh: mm: SS, SSS}. The 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. Example: testlog4.main (testlog4.java: 10)
This blog is more perfect for better performance...
Provides configuration files
Web. xml
<?xml version="1.0" encoding="UTF-8"?><web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"> <servlet> <description>This is the description of my J2EE component</description> <display-name>This is the display name of my J2EE component</display-name> <servlet-name>initLogger</servlet-name> <servlet-class>servlet.initLogger</servlet-class> <init-param> <param-name>log4j</param-name> <param-value>WEB-INF/log4j.properties</param-value> </init-param> <load-on-startup>1</load-on-startup> </servlet> <servlet> <description>This is the description of my J2EE component</description> <display-name>This is the display name of my J2EE component</display-name> <servlet-name>c</servlet-name> <servlet-class>servlet.c</servlet-class> </servlet> <servlet-mapping> <servlet-name>c</servlet-name> <url-pattern>/c</url-pattern> </servlet-mapping> <welcome-file-list> <welcome-file>index.jsp</welcome-file> </welcome-file-list></web-app>
Sevlet initlogger. Java
Package servlet; import Java. io. file; import Java. io. ioexception; import Java. io. printwriter; import java.net. malformedurlexception; import java.net. urisyntaxexception; import java.net. URL; import javax. servlet. servletexception; import javax. servlet. HTTP. httpservlet; import javax. servlet. HTTP. httpservletrequest; import javax. servlet. HTTP. httpservletresponse; import Org. apache. log4j. propertyconfigurator; import Util. dao; public class initlogger extends httpservlet {/*****/Private Static final long serialversionuid = 7010497166323512560l;/*** destruction of the servlet. <br> */Public void destroy () {super. destroy (); // just puts "Destroy" string in log // put your code here}/*** the doget method of the servlet. <br> ** this method is called when a form has its tag Value Method equals to get. ** @ Param Request * The request send by the client to the server * @ Param response * The response send by the server to the client * @ throws servletexception * if an error occurred * @ throws ioexception * If an error occurred */Public void doget (httpservletrequest request, httpservletresponse response) throws servletexception, ioexception {response. setcontenttype ("text/html"); printwriter out = response. getw Riter (); Out. println ("<! Doctype HTML public \ "-// W3C // dtd html 4.01 transitional // en \"> "); out. println ("<HTML>"); out. println ("
Execution method C. servlet
Package servlet; import Java. io. ioexception; import Java. io. printwriter; import javax. servlet. servletexception; import javax. servlet. HTTP. httpservlet; import javax. servlet. HTTP. httpservletrequest; import javax. servlet. HTTP. httpservletresponse; import Org. apache. log4j. logger; import util. bar; public class C extends httpservlet {/*** the doget method of the servlet. <br> ** this method is called when a form Has its tag Value Method equals to get. ** @ Param request the request send by the client to the server * @ Param response the response send by the server to the client * @ throws servletexception if an error occurred * @ throws ioexception if an error occurred */Private Static logger = logger. getlogger (C. class); Public void doget (httpservletrequest request, httpservletresponse response) throws Servletexception, ioexception {logger.info ("don't accept your TM !!! ");}/*** The dopost method of the servlet. <br> ** this method is called when a form has its tag Value Method equals to post. ** @ Param request the request send by the client to the server * @ Param response the response send by the server to the client * @ throws servletexception if an error occurred * @ throws ioexception if an error occurred */Public void dopost (httpservletrequest request, HTTPS Ervletresponse response) throws servletexception, ioexception {response. setcontenttype ("text/html"); printwriter out = response. getwriter (); Out. println ("<! Doctype HTML public \ "-// W3C // dtd html 4.01 transitional // en \"> "); out. println ("<HTML>"); out. println ("
PS: Beginner's note
log4j.appender.appender1=org.apache.log4j.DailyRollingFileAppender
org.apache.log4j.DailyRollingFileAppender
log4j.appender.appender1=org.apache.log4j.FileAppender
Their things are different. They take effect only when you specify some parameters.
I often say that, for example, examples can make words more persuasive.
For example
For example, you used this
log4j.appender.appender1=org.apache.log4j.FileAppender
These are invalid...
#7 define the maximum length of the A2 output file log4j. appender. appender1.maxfilesize = 2kb #8 define the number of A2 backup files log4j. appender. appender1.maxbackupindex = 2
This article is online-currently the most comprehensive paste available .... Unavailable, IQ unavailable, or incorrect version. Version 2.0 is not supported .. Thank you.
Log4j is a perfect configuration file!