. logfactory; public class connectionmanager {// connect to the Oracle class Private Static log logger = logfactory. getlog (connectionmanager. class); // print it to the log file. The path is configured in the log4j file. Private connection conn = NULL; public static connection getconnection () throws Exception {datasource DS = getdatasource (); Return Ds. getconnection ();} public static datasource getdatasource () throws exception {try {javax. nami
Many diaosi think that log4j is not easy to use because it is not output to the IDE console. Haha, it is actually a disaster caused by configuration. The following describes how to configure log4j to the console step by step,
I believe that log4j's output level and output mode are all known. I will not talk about it here. Let's just look at the code comment:
# Al
:%d{yyyy MMM dd hh:mm:ss,sss}, output similar to: October 18, 2002 22:10:28,921#%l where the output log event occurs, including the class name, the thread that occurred, and the number of rows in the code. Example: Testlog4.main (testlog4.java:10)Examples of formatting:LOG4J.APPENDER.THISPROJECT.FILE.OUT.LAYOUT.CONVERSIONPATTERN=LOG4J--GT;%D{YYYY MMM DD HH:mm:ss,SSS}%5p{%F\:%L}-% m%nAttention:1. Small knowledge of information formattingThese parameter
configure log4j with XML or Java at run time, the properties file is useful.
Log4j.rootlogger=info, stdout
Log4j.appender.stdout=org.apache.log4j.consoleappender
Log4j.appender.stdout.layout=org.apache.log4j.patternlayout
# to output the caller ' s file name and line number.
log4j.appender.stdout.layout.conversionpattern=%5p [%t] (%f:%l)-%m%n
Analyze:
First line, configure Log4j.rootlogger you know. It should be the root, must be configured, otherwis
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 each log, and by defining the level of each log information, we can control the log generatio
The use of log4j logging is very convenient, it provides two types of log configuration, log4j.propertes and Log4j.xml, this document first posted Log4j.properties configuration method
1. Brief analysis of log4j.properties file configuration
The following gives the log4j.properties file commonly used in some informatio
Appenders configuration of log4j, log4jappenders
Because log4j was used at the beginning, many configuration items were not understood and recorded.
The following is a log4j. xml configuration file automatically generated by me wh
In general, some important logs in our project want to be output to the specified file separately, instead of the total output to the System Log File. Therefore, log4j provides us with this function, next, let's take a step-by-step look at how it works. This is written in the property configuration mode. The XML method is similar. For more information, see the official documentation.
The project package str
First, a new log4j.properties file can be created in the classes of the project; In the actual programming, in order to make the log4j really run in the system in advance also to define the configuration file. The defining step is to use the logger, Appender, and layout separately. LOG4J supports two configuration file
First, a new log4j.properties file can be created in the classes of the project; In the actual programming, in order to make the log4j really run in the system in advance also to define the configuration file. The defining step is to use the logger, Appender, and layout separately. LOG4J supports two configuration file
root directory of the project and not in the SRC directory of the project.(2) in the Javaweb project, it is placed in the SRC directory, because this time Tomcat will go to the default loading it, do not need us to manually load the log4j configuration file, only need to configure the configuration to obtain their own required logger instance can be, So we know
Spring Oauth2 In most cases is still not used, the main use is spring+springmvc+hibernate, sometimes with springsecurity, therefore, This article and the future article example will not contain the OAUTH2 configuration, need to put the former Applicationcontext-security.xml and Pom.xml plus on it, this article in the "ssh+spring Security building methods and example "the article is based on a number of adjustments, the main content is: Configure Sprin
OG4J specific output information level configuration method
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
Og4j Advanced Tips-Location of dynamic configuration log output files
The usual use of log4j is to write the output file directly to death in its configuration file (XML or properties), which in many cases is very simple and effective. The disadvantage of this is that if you want this Web application to run, you have to modify the
In the whole web system, in order to unify the use of log management, it is necessary to load the log4j configuration file when the system is started, in order to ensure that the format of the later use of log4j is consistent, easy to track and solve the problem. So, how to load the log4j
log4j configuration file is not initialized under Classpath
Specify the location of the log4j.properties configuration file, while dynamically setting the output location of the log:
private static Logger Logger = null;
static{
//Set the environment variable property Workdir as the installation directory, so workdir can get the value of this environment vari
The log4j configuration file is used to set the level, the repository, and the layout of the logger, which can be set in key=value format or in XML format.By configuration, you can create a running environment for log4j.1. The basic format of the configuration file
operations that log records are processed.Its syntax is:Log4j.rootlogger = [level], Appendername, Appendername, ...Level is the priority of logging, which is divided into off, FATAL, ERROR, WARN, INFO, DEBUG, all, or your own defined levels. LOG4J recommends using only four levels. Priority levels from high to low are error, WARN, INFO, DEBUG, respectively. By the level defined here. A switch that you can control to the corresponding level of log inf
One, add log4j dependency PackageThe dependency package Log4j-x.x.xx.jar can be downloaded from the official website, and after the download build path, add dependency packages such as using MAVEN, you can add the following dependencies https://mvnrepository.com/artifact/log4j/log4j - Dependency> groupId>Log
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.
1. configuration fileThe
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.