The configuration fails according to many configuration steps on the Internet. Now let's look back at the inconsistency of most versions.
In addition, log4j is flexible in addition to managing logs for the entire container, it can also manage logs for a project. If there are only logs in the container, what should we do with the logs in JUnit? Therefore, project
Log4j It consists of three important components: log information priority, log information output destination, and log information output format. The priority of log information ranges from high to low. Error , Warn , Info , Debug To specify the importance of the log information. The log output destination specifies whether the log will be printed to the console or a file. The output format controls the display of the log information. 1, D
I have said before about the major use of Java Log Tracking framework, also said, in fact, in which log4j plays a very important role. At present, most of the framework is also the use of log4j, although it has stopped the update, the author also re-logback the project, but Logback currently in the domestic use is quite small. Most of the current projects still use log4
Logging naturally is very important, but I am afraid to remember slf4j and log4j, such as the configuration of the log framework is very few people, this thing is not difficult, but only after the configuration is rarely to move it, the development of new projects are usually copied from other projects, or reference to the documentNeedless to say, say
Today, I made a one-day remote log configuration. Due to the lack of documents and strategies, debugging was very difficult. Most of the items searched on the Internet are only code-based and do not describe the principles at all. Finally, the configuration is successful, and now the process is organized as follows.
Summary: socket-based remote log is composed of the server and client. The server needs to s
The website is about to be released. To track some logs, you need to use log4j. So I studied the configuration of log4j.
First, paste a configuration source file log4j. properties.
log4j.rootLogger=DEBUG, CONSOLE, FILE## for consolelog4j.appender.CONSOLE=org.apache.log4j.Co
In the selection of slf4j-api-1.7.7.jar + slf4j-log4j12-1.7.7.jar + log4j-1.2.17.jar output (the premise is that there is a corresponding configuration file log4j. properties, put in the root directory, usually SRC folder) to the file logs. log and errors. Log
1. The basic format is as follows:
# Configure root loggerlog4j. rootlogger = [level], appendername1, a
}" for jar in $lib _path/*.jardoif ["$CLASSPATH" = ""];Thenclasspath= $jarelseCLASSPATH = $CLASSPATH: $jarfidoneexport classpath= $CLASSPATHecho "java ${main_class} \" [Email Protected]\ ""4. Right-click Project-debug as-maven assembly:assemblyThe output log is packaged successfully.Four. Testing1. Unzip the zip file, the folder structure is as follows, all files are present:2. Enter the bin and run the Start.bat (the JRE environment needs to be installed in the running environment)3. The result
The log4j configuration file (Configuration file) is used to set the level, the repository, and the layout of the logger, and it can be set in key=value format or in XML format information. By configuring, you can create a log4j running environment. The log4j
4Basic log4j Configuration
Log4j consists of three important components: loggers, appenders, and layouts, which respectively indicate the priority of log information, the output destination of log information, and the output format of log information. Supports key = value format setting or XML format setting.
L the priority of log information ranges from high to
In emphasizing reusable component development today, in addition to developing a reusable log operation class from beginning to end, Apache provides us with a powerful log-handling package-log4j.Log4j is an open source project for Apache, by using log4j, we can control the destination of log information delivery is console, file, GUI component, even interface server, NT Event recorder, UNIX syslog daemon, etc. We can also control the output format of
# -- Log4j. rootlogger: output the log information with the info level to the stdout and file destinations. The definitions of stdout and file can be named in the following code. Levels can be divided into off, fatal, error, warn, info, debug, and all. If off is configured, no information is displayed. If Info is configured, only info, warn is displayed, error Log information, while debug information is not displayed
: once where
daysThe programmer decided not to display the System.out.println, but to comment out the spam statements on a line. If where
daysIf you want to debug variable values, you can only remove these comments in a row to recover the SYSTEM.OUT.PRINTLN statement.
Using log4j can be a good treatment for similar situations. Log4j use method The following is a log4j
Log4j configuration is commonly used. Two methods are generally used:. properties and. xml. The following two simple examples are provided:1. log4j. Properties
### Set Org. level info, debug, warn, error, and output location a1, a2 # log4j.category.org. zblog = error, A1 log4j.category.org. zblog = info, A2 log4j. app
configuration file
LOG4J supports two types of configuration file formats:
1. XML-formatted files
2. File in properties format
You can also configure the LOG4J environment in code without using a configuration file at all. However, using a
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
When the project is on-line, the runtime often also has an exception, in the exception throws, want to get feedback immediately. So you need to configure the log4j send email function.The original version of log4j used in the project is 1.2.9, but this version does not support the authentication function of the mail service, so the latest version 1.2.14 is downloaded again to view the source codeThis versio
# 3. WARN # 4. ERROR # 5. FATAL (the most serious) # Set Root logger level to WARN and append to stdout Log4j.rootlogger=debug, stdout log4j.appender.stdout=org.apache.log4j . Consoleappender Log4j.appender.stdout.target=system.out log4j.appender.stdout.layout= Org.apache.log4j.PatternLayout# Pattern to output the caller's file name and line number.#单条日志的显示格式 log4j.appender.stdout.layout.conversionpattern=%d{yyyy-mm-dd Hh:mm:ss,sss}%p%c.%m (%L):%m%n# Print only messages of level ERROR or abo
Log4j configuration is commonly used. Two methods are generally used:. properties AND. xml. The following two simple examples are provided:1. log4j. properties
### Set org. level INFO, DEBUG, WARN, ERROR, and output location A1, A2 # log4j.category.org. zblog = ERROR, A1log4j.category.org. zblog = INFO, A2log4j. appender. a1 = org. apache.
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.