Alibabacloud.com offers a wide variety of articles about spring log4j configuration example, easily find your spring log4j configuration example information here online.
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
A brief introduction to the use of Org.apache.log4j.Logger in the MAVEN project.[1] First we need to find the coordinates of Org.apache.log4j.Logger and configure to Pom.xmlDependency> groupId>Log4jgroupId> Artifactid>Log4jArtifactid> version>1.2.14version> Scope>ProvidedScope>Dependency>[2] By default, you need to add a configuration file under the Src/main/java folder Log4j.properties, the specific content can be referenced below a simple example:Lo
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 display
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
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
[Spring tutorial] create a simple spring example, spring Tutorial example
1. First, the main idea of spring is dependency injection. Simply put, there is no need to manually create new objects, and these objects are managed by the
configuration of the reader, and not be directly covered blindly ...Third, MySQL optimization programMySQL optimization, side dishes learned is to modify the maximum number of connections, because MySQL default maximum number of connections is 100, for a slightly larger project, is certainly not enough.Project-Side ConfigurationThe maximum number of connections, first set in the program, if your project uses a JNDI
Note: this information is searched through the network and then sorted into
First of all, to explain the parameters of the configuration file, so that the configuration can be reasonable.
Description of parameter meaning:
Configure Root Logger
Its syntax is:
Log4j.rootlogger = [level], appenderName1, appenderName2, ...
Level: Is the priority of the logging, divided into
the levels you define by off, FAT
A. log4j.properties file Format Description:log4j.rootlogger=info, stdout log4j.appender.stdout=Org.apache.log4j.ConsoleAppenderlog4j.appender.stdout.layout=org.apache.log4j.PatternLayout# Pattern to output the caller's file name and line number. log4j.appender.stdout.layout.conversionpattern=% 5p [%t] (%f:%l) - %m%n first line, configure log4j.rootlogger > you get it. should be root for it, log4j.rootlogger=info, stdout, file The info here indicates that the log level is info, a
In general, we will directly log4j.properties placed in the SRC directory, so that the system will automatically find, in fact, is placed under the Web-inf/classes file. This path is classpath, so you can find it directly. We wrote the logger as follows
public class Hellolog4j {public static Logger Logger = Logger.getlogger (Hellolog4j.class);
public static void Main (string[] args) {Logger.debug (' This is debug message. ');
Logger.info ("This is info.");
Logger.error ("
Spring for cainiao-first example, spring for cainiaoI. OverviewWe used the factory for flexible configuration. Now, after Spring is used, this is handed over to IoC container management. We only need to match the XML file, which saves a lot of development time. We don't need
Sometimes it is necessary to print the debug information of the third party jar when checking the problem, if all jars are printed, the log file will be very large, this time can be configured log4j to print only the specified jar debug information or package, and output to a new file.For example: I only printed here MyBatis below DataSource This package debug information to the Debug.logLog4j.logger.org.ap
Log4j a total of 5 log output levels:
FATAL (0)
Example:
Log4j.rootlogger=debug,console, FileThe above settings can fetch the throw new RuntimeException ();Log4j.rootlogger=info,console, FileThe info level will not catch the throw new RuntimeException ();
The reason is that this error belongs to DEBUG level debug>info>error so INFO cannot be caught
Console output log information
About Tomcat under multiple projects configure a log4j.properties, to output the respective log of the problem,
After the actual work of the summary and investigation, here to make a summary and memo.
To lift the log4j configuration, our common configuration method is to create a log4j.properties file for each project and write the information of its own output
LOG4J has a total of 5 log output levels:
FATAL (0)
Example:
Log4j.rootlogger=debug,console, FileThe above settings can crawl throw new RuntimeException ();Log4j.rootlogger=info,console, FileInfo level can not catch throw new RuntimeException ();
The reason is that this error belongs to the DEBUG level debug>info>error so INFO can't catch it.
Console output log information
a lightweight framework or a weight framework? Whether an application is lightweight or heavyweight depends on how many services it uses. the more services you use, the more work containers need to do for common Java objects, which will inevitably affect the application release time or running performance.
For spring containers, it provides many services, but these services are not opened by default for the application. The application requires a ce
the/var/log folder for Spring.log
Note: Both cannot be used at the same time, and only logging.file effective if used simultaneouslyBy default, the size of the log file is sliced once at 10MB, creating a new log file with the default level: ERROR, WARN, INFO level control
All supported logging systems can set the logging level in the spring environment (for example, in application.properties)The format is:
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.