Logger is the core component of log processing. Log4j has five levels ). The available level of the logger (excluding the Custom Level), which is taken from the log4j API (http://jakarta.apache.org/log4j/docs/api/index.html ):
Static level debug
Debug level indicates that fine-grained information events apply to debu
A simple search from the Internet, found that there are three ways to introduce. Summary here
1.
The solution is naturally to find ways to use the relative path to replace the absolute path, in fact, log4j Fileappender itself has such a mechanism, such as:
Log4j.appender.logfile.file=${workdir}/logs/app.log
where "${workdir}/" is a variable that is replaced by the value "Workdir" in the system property. This allows you to set the root path with System
It programmer development Essentials-all kinds of resources download list, history of the most IT resources, personal collection summary.
How to log logs using log4jFirst step: Add the jar file used by log4j in the project1: Project > Properties: Popup Project's Properties window2:java construction Path; add an external jar: pops up the window that selects the jar3: By selecting the Jar window, locate the
The various configuration items in the output log format are described below:
Parameters
Description
Example
%c
Lists the full name of the logger namespace, if the {
log4j configuration File Parameters Example
Output Display Media
Suppose the current logger namespace is "A.B.C"
%c
A.b.c
%C{2}
B.c
%20c
(If
Log4j. appender. mylogfile. File = E:/logs/test/Main. LogThe above line is a typical log4j log file path configuration. Then, can I
ProgramTo output logs to different paths. The answer is yes, instance
CodeThe following Java code:
Public static logger getloggerbyaccout1 (string accout) {If (null = rootlog) {system. setproperty ("myconfig. accout ", accout); ro
Do one of the simplest servlet projects, with only one servlet, and then want to record the logs in the servlet to the LogRecord.log and LogRecorderror.log in the Logs folder under the project.
However, the path problem has made me a day, find a lot of information, the absolute path can be solved, but if the transplant, then the absolute path will be very troublesome to change. So it's best to use relative paths.
But the relevant information on the Internet can not solve my problem, later pound
The encoding format of the log file to be output by log4j is the UTF-8.Under normal circumstances, you only need to add the following code:
Log4j. appender. appender_name.encoding = UTF-8
However, this method becomes invalid when spring and log4j are integrated. The reason is not discussed in depth. It seems that spr
1. Introduction to the log systemSLF4J, the simple log façade (easy Logging facade for Java), is not a specific log solution, it only serves a wide variety of log systems. The simple answer is that SLF4J is a series of log Interfaces , and
Creating a journal in a project is necessary for a project, now used more widely, more popular log tools have log4j; This log tool is actually very convenient to use; I know her is also deep, but at the time when the need to use is really unprepared, know how to configure but just do not know how to use, Waste a lot of time;Today is the way to write a quick start
Log4j log priority causes no output logs.
When deploying the code in sae, it finds that its default log is unfriendly and looks very difficult. After a detailed look, it shows that it can be output by log4j output level, drag a log4j xml file into the project code and deploy
1: Establish log4j.properties files
2: Placement Path/web-inf/classes
3: The standard contents are as follows
------------------### Direct log messages to stdout ###Log4j.appender.stdout=org.apache.log4j.consoleappenderLog4j.appender.stdout.target=system.outLog4j.appender.stdout.layout=org.apache.log4j.patternlayoutLog4j.appender.stdout.layout.conversionpattern=%d{absolute}%5p%c{1}:%l-%m%n
### Direct messages to file Hibernate.log ####
Some log operations, such as debugging information in the development stage, running logs, and auditing, are often used during programming. The survey shows that the Log Code accounts for 4% of the total code. Generally, you can simply use the System. out. println () statement to output log information, but there are usually some judgments, such:
If(SomeCondi
This article resolves the minimum and log-related packages required to build a LOG4J Log framework project:Commons-logging-xxx.jarLog4j-xxx.jarSlf4j-api-xxx.jarSlf4j-log4j12-xxx.jarInterested comrades can continue to look at the following:The current open source log framework for Java is mainly divided into 2 tiers:1)
The logs in the project need to adopt a consistent naming convention and File specification: Project module Identification _index_ Date Time _ Log level. log, and each level log file in a separate folder, and the number of logs under each folder must not exceed 10, when the number exceeds the limit, delete the relatively old
Previously developed systems do not have a separate log management, all the log unified output to a file in tomcat background, a few days is several G, now to the overall increase of a log4j management log function, in fact, the information on the Internet is many. The configuration of the message also has, but the spe
First, log4j configuration
The first step: Join Log4j-1.2.8.jar to Lib.
Step two: Establish the log4j.properties under the classpath. The contents are as follows:
If you put it under SRC, you don't have to configure it or you have to go to Web.xml to configure a listener
Reference:
Log4j.rootcategory=info, stdout, R log4j.appender.stdout=org.apache.log4j.consoleappender log4j.appender.stdout . Layout=org.a
Configure interval time, print log periodicallyreceived a demand, through the log4j time print log, requirements described as follows: the need to be able to print the log regularly, the interval can be matched. When it comes to timing, first think of the Dailyrollingfileappender class, various timing, according to Dat
The production of a log in the project is necessary for a project, now used in a more extensive, more popular log tools have log4j; This log tool is actually very convenient to use, and when used, it was created like Java.util.logging.Logger, The JDK log logging information
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.