The default log framework provided by hibernate3 is slf4j. The SLF of hibernate3 is only a log interface, while the default log framework provided by hibernate3 is rarely used by companies or projects in actual development, here we record a log framework that uses log4j to replace the implementation of the slf4j log framework. The specific configuration and implementation are as follows:
I. added the
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
SPRINGMVC+HIBERNATE+LOG4J+SLF4J is used in the application. The log level of the log4j is tuned to info. However, when the Web container (Tomcat) starts and runs, the debug-level logs in the spring,hibernate frame are constantly being brushed, causing the log file to soar and the disk to explode in a few days.
In response to this problem on the Internet to find a lot of methods, are no effect or palliative
Preface
I've been saying, how to read the Log4j profile log4j.properties.
The next discussion is: How to set the path of the log file created in log4j.
Tomcat's okay. For complex WebLogic, this is how to set the path, because it doesn't understand how to press the war file.
In the last article
Also mentioned in the log (log4j)
Log4j is a Java-based open-source log component. log4j has powerful functions. We can output log information to the console, files, and user interfaces, it can also output Event recorders and some system resident processes to the operating system. It is worth mentioning that log4j allows you to easily customize log formats and log levels, and helps developers ful
The three main components of the log4j configuration file are:Logger,appender and layout, respectively, log type, log output destination, log output format.Log4j.rootlogger = [Level],appendername, Appendername, ...(Level is the error, Appendername is the output destination, this example is set to MyLog, you can define more than one) level priority is fatal, ERROR, WARN, INFO, DEBUG 5 levels. By defining the
. - - Log4j.appender.stdout=org.apache.log4j.consoleappender the #log4j. Appender.r=org.apache.log4j.dailyrollingfileappender - #log4j. Appender.r.file=/data/logs/nmc/txp-log - - + - + This sentence is the type of layout that defines the output named stdout, which can be A org.apache.log4j.HTMLLayout (Layout in HTML table Form), at Org.apache.log4j.PatternLayout (flexibility to specify layout mode),
Use the background:Apache log4j is a powerful log file that we need to know how our configuration files are loaded and how they are loaded when we use the IDE to configure log4j in the project.Load Mode:(1), automatically load the configuration file:LOG4J will default to find the source folder's
# ${webapp.root}: Log files are stored in the project directory ${catalina.home}: Log files are stored in the Tomcat directory
XML configuration Mode 1
The maximum number of log files configured for Maxbackupindex is 20, each log file size is 10MB. Save different levels of log information to different files: Debug.log, Info.log, Warn.log, Error.log, etc.
When the number of log files reaches 20, this
}, output similar to: 2002-10-18-22:10:28
%f The class name of the class to which the output log information belongs
%l The occurrence of the output log event where the statement that outputs the log information is in the first line of the class it is in
%m The information specified in the output code, such as a message in log (message)
%n Output a carriage return newline character, Windows platform is "RN", UNIX platform is "n"
%p output priority, or debug,info,warn,error,fa
If you use the spring plug-in to create a spring template project, it defaults to log4j, as long as you change the log4j configuration to use, if you create a project, you need to load the log4f package, use the following steps
1.pom.xml join Log4j's dependency pack
2. Create Log4j.xml under Src/main/resources
Log4j.xml defines 3 Appender, which is the location
You need 4 jar packages first. As followsHttp://pan.baidu.com/s/1i4k3fiHThe following package is included in the interim and can be placed in the project Lib.In addition to the need for a configuration file, the sharing link is as follows. Http://pan.baidu.com/s/1o7qy2Ky put the configuration file in the location. Name yourself, then go to the project and use it.Import Org.slf4j.Logger;Import Org.slf4j.Logg
1. log4j (log4j.properties) configuration file
Define the log configuration file and place it in the Web-info directory.
LOG4J.LOGGER.OPERATELOG=INFO,A1
# # #输出到日志文件 ###
log4j.appender.a1= Org.apache.log4j.DailyRollingFileAppender
log4j.appender.a1.file=e:\\file.log
log4j.appender.A1.layout =org.apache.log4j.patternlayout
log4j.appender.a1.layout.conversionpatte
1, the first page in the Web-inf directory under the new log4j.properties configuration file, the contents are as follows: log4j.rootcategory = Info,dailyfile log4j.appender.dailyFile =org.apache.log4j.dailyrollingfileappenderlog4j.appender.dailyfile.threshold = DEBUG log4j.appender.dailyFile.ImmediateFlush =true log4j.appender.dailyfile.append =true log4j.appender.dailyfile.file =c:/logs/ Log.loglog4j.appender.dailyFile.DatePattern =yyyy-mm-d
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 is obtained and exported using the handler object, and the exported information is formatted by formatter object and log4j log informat
Some configuration of log4ja). New Java project>> new package>> new Java class;b). Import jar Package (one is enough), here I use Log4j-1.2.14.jar,c). Create a new log4j.properties, placed under project root;
Log4j.rootlogger=info, Serverdailyrollingfile, stdoutLog4j.appender.serverdailyrollingfile=org.apache.log4j.dailyrollingfileappenderLog4j.appender.serverdailyrollingfile.datepattern= '. ' Yyyy
log4j Introduction log4j has three main components: loggers (Logger), appenders (output source), and layouts (layout). This can be simply understood as the log category, where the logs are to be exported and how the logs are exported. The combined use of these three components makes it easy to record the type and level of information, and to control the style and location of the log output at run time. 1. L
When log4j is called to output logs in XXX class, the following statement is called at first,
Public static logger = org. Apache. log4j. Logger. getlogger (class name. Class. getname ());
This method can be used to set the Log Level of the class in the configuration file. For example, add the following lines to the configurat
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.