Alibabacloud.com offers a wide variety of articles about spring log4j configuration example, easily find your spring log4j configuration example information here online.
I use the MyEclipse6.0 Spring version is 2.0; the quartz version is 1.5.2;
Main steps:
To create a new Web project:
First, the jar package is imported: Quartz-1.5.2.jar,spring.jar (both of them are enough);
Then configure Web. XML:
Then configure the spring configuration file: Applicationcontext.xml
The last is the test class: First.java
Package com.mc.job;
I'm using the MyEclipse6.0 Spring version is 2.0; Quartz version is 1.5.2;
Main steps:
New Web project:
First Import jar package: Quartz-1.5.2.jar,spring.jar (with these two is enough);
Then configure Web.xml:
Then configure the spring configuration file: Applicationcontext.xml
The last is the test class: First.java
Package com.mc.job;
public class-A-
stat
Spring + AOP + Log4j uses annotations to record logs of a specific method.
I. Description of spring aop execution expressions
When using the spring framework to configure AOP, you must define pointcut "entry point" in both XML configuration files and annotations"
For
1. Basic Configuration
# The simplicity of log4j configuration makes it more and more widely used # The log4j configuration file outputs to the console, files, rollback files, send log emails, and output to the database log tables, custom tags, and other functions. # General
LOG4J can be configured by using a configuration file.The configuration steps are as follows: 1. Define the Log component loggerEach logger can have one or more appender, each appender representing the output destination of a log, such as the console or a file.The syntax for configuring root logger is:Log4j.rootlogger=[priority],appendername,appendername,...-The
}web-inf/logs/error.log log4j.appender.e.file.maxfilesize=500kblog4j.aPpender. E.append = true## Only output logs above the error level!!! Log4j.appender.e.threshold = Errorlog4j.appender.e.layout = Org.apache.log4j.patternlayoutlog4j.appender.e.layout.conversionpattern =%-d{yyyy-mm-dd HH:mm:ss} [%t:%r]-[%p]%m %nlog4j.appender.e.encoding=utf-8Configure the Info-level output to the console, and debug and error are output to the corresponding file. 4. Using the Log ObjectImport Org.slf4j.logger;im
, thread, category, etc.) of the logConfiguration mode:Log4j.appender.appenderName.layout =classnameLog4j.appender.appenderName.layout.Option1 = value1...Log4j.appender.appenderName.layout.OptionN = ValuenSecond, configuration detailedIn the actual application, in order to make the log4j run in the system, the configuration file must be set beforehand. The
to console. The next two lines are set log format, usually you copy it.
In the actual project development, it is likely to encounter the quoted package log4j to log, such as Hibernate. So here you can easily control how the packet logs. For example, add a line to the above configuration file:
Log4j.logger.org.hibernate=fatal
Then all the classes below the Org.h
It has been a while since you used log4j for log output in spring, but sometimes you find that log files are already stored according to their ideals, but there are some baffling project log files that appear in Tomcat (because the project's log files are named after the project). So it's easier to distinguish between these logs. These are my tangled log files, let me improve the
Take the MAVEN Web project as an example,First, in the Pom file to introduce relevant dependencies, as follows (spring official documents are described):The log framework used by default in spring is: commons-logging (to exclude this dependency), introducing a "jcl-over-slf4j" dependency, which makes spring's call to common-logging a call to SLF4J.Note that when
, thread, category, etc.) of the logConfiguration mode:Log4j.appender.appenderName.layout =classnameLog4j.appender.appenderName.layout.Option1 = value1...Log4j.appender.appenderName.layout.OptionN = ValuenSecond, configuration detailedIn the actual application, in order to make the log4j run in the system, the configuration file must be set beforehand. The
name and row number are output. -Title = My app file: The default value is log4j log messages. 2) patternlayout option-conversionpattern = % m % N: specify how to format the specified message. 3) xmllayout option-locationinfo = true: the default value is false, and the Java file and row number are output. Part 2: log4j. appender. a1.layout. conversionpattern = %-4r %-5 p % d {yyyy-mm-dd hh: mm: SSS} % C %
Step 1: Configure the log4j configuration file.
1. Root directory Configuration: example: Log4j.rootlogger = info,console,daily
The level of the info log output, typically 4 levels of error, warn, info, debug; Logs below this level will not be output
console,daily the log output, the following will also continue to con
, thread, category, etc.) of the logConfiguration mode:Log4j.appender.appenderName.layout =classnameLog4j.appender.appenderName.layout.Option1 = value1...Log4j.appender.appenderName.layout.OptionN = ValuenSecond, configuration detailedIn the actual application, in order to make the log4j run in the system, the configuration file must be set beforehand. The
, thread, category, etc.) of the logConfiguration mode:Log4j.appender.appenderName.layout =classnamelog4j.appender.appendername.layout.option1 = value1 ... Log4j.appender.appenderName.layout.OptionN = ValuenSecond, configuration detailedIn the actual application, in order to make the log4j run in the system, the configuration file must be set beforehand. The
and path in 4.1 web.xml
4.2 log4j.properties File Configuration Example
##### #配置输出日志的目录和输出日志的级别 ########## #rootLogger: Set the log of all logger objects configured under the output root (classpath) #第一个参数Debug: What level of log output? The second parameter stout: which appender to output (multiple Appender can be configured, such as: Df_debug,df_error) #log4j
-%m%n#OtherLoggerlog4j.logger.org.springframework=INFOlog4j.logger.com.ibatis.db=INFOlog4j.logger.net.sf.json=ERRORlog4j.logger.org.apache.cxf=DEBUG,WS
Note: My configuration file here is not very good, for reference only(4) Test:
1234567891011121314151617
packagecn.zifangsky.controller;importorg.apache.log4j.Logger;importorg.springframework.stereotype.Controller;importorg.springframework.web.bind.annotation.RequestMapping;@Co
Source and discussion: http://www.blogjava.net/calvin/archive/2005/12/31/26150.html
Author: Jiangnan Baiyi
Spring is best at adding cream to other cakes, which makes your J2EE without spring itch.
Log4j can have the following cream:1. dynamically change the record level and policy without restarting the web application, as described in effective Enterprise Java.2
, thread, category, etc.) of the logConfiguration mode:Log4j.appender.appenderName.layout =classnameLog4j.appender.appenderName.layout.Option1 = value1...Log4j.appender.appenderName.layout.OptionN = ValuenSecond, configuration detailedIn the actual application, in order to make the log4j run in the system, the configuration file must be set beforehand. The
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.