The following is written in the official log4j API, which is sufficient to explain the difference between logger and category...
public class Category
Extends java. Lang. Object
Implements appenderattachable
This class has
name is similar to the package in Java, case sensitive, separated by dots and has an inheritance relationship. Logger properties are configured by name in Log4j.properties.
3, when the logger instance is named, there is no limit, you can take any name you are interested in. In general, it is recommended to name the logger instance where the class is located, which is a more effective logger naming method at the moment. This allows each class to establish its own log information for easy manage
Printing method: Public voidlog (level L, Object message);}It is also very simple to use in a program, which is to get a logger instance and then call different methods to get different types of log information: Public classMain {//get the Rootlogger method Public StaticLogger Rootlogger =Logger.getrootlogger (); //Get the Custom logger method Public StaticLogger Logger = Logger.getlogger (Main
configuration file, the code is as follows:[Php]Log4php. rootLogger = DEBUG, A1Log4php. appender. A1 = LoggerAppenderEchoLog4php. appender. A1.layout = LoggerLayoutSimple[/Php]No matter what the code means, create a new log4php. properties file in the app Directory, copy the above code to the file, and save it.Note:1. the file name must be log4php. properties. do not write an error.2. this file must be the same as index. php, that is, under the app d
= Org.apache.log4j.DailyRollingFileAppenderLog4j.appender.A1.File = D:/abc/test.logLog4j.appender.A1.Append = TrueLog4j.appender.a1.datepattern=yyyy-wwLog4j.appender.A1.Threshold = infoLog4j.appender.A1.layout = Org.apache.log4j.PatternLayoutLog4j.appender.A1.layout.ConversionPattern =%5p%10d{yyyy-mm-dd HH:mm:ss} {%l}%m%nFor the above configuration does not understand can Google, here to say the threshold configuration, here threshold configuration is info, but
Log4j configuration file and log configuration in the nutch
When SLF4J is used as the log system, SLF4J is only an interface and needs a specific implementation for execution.
Reference
Slf4j unifies API interfaces. Therefore, if log4j is used to output logs, you only need to set the content of the configuration file. The configuration in log4j. properties can be divided into two categories:
The first type defines the log output level and appender)
The second class defines the specific attribute
layout mode)Org. apache. log4j. SimpleLayout (Level and string of log information)Org. apache. log4j. TTCCLayout (including the log generation time, thread, category, and other information)Configuration Mode:Log4j. appender. appenderName. layout = classNameLog4j. appender. appenderName. layout. Option1 = value1...Log4j. appender. appenderName. layout. OptionN = valueNIi. configuration detailsIn practical applications, configuration files must be set in advance for Log4j to run in the system. Th
1. Logger class
Use the static logger method logger. getrootlogger of the logger class to obtain the rootlogger. All other loggers are instantiated and obtained through the static method logger. getlogger. In this method, logger. getlogger takes the name of the logger as the parameter. Some other basic methods of the logger class are listed below:
Package org. Apache. log4j; Public class logger { // Creation and retrieval methods
In our project, there are some important logs to separate output to the specified file, rather than the total output to the system log file, then we log4j for us to provide such a function, below we have to step by step to see how to do. This is written in the configuration of the property, XML is similar, you want to know, you can see the official document.
The project package structure tested here is as follows:
Log4j mainly consists of three parts: loggers, appenders and layouts, (Appender c
First, create a new log4j. properties file in the project classes; In actual programming, you must define the configuration file before making log4j really run in the system. The definition step is to use logger, appender, and layout respectively. Log4j supports two configuration file formats: XML and Java properties (Key = value) [Java feature file (Key = value )]. (Only the properties file is described here) 1. Configure the root Logger Its syntax is:Log4j.
I have already explained how to use log4cxx for logging. Today the problem is a little complicated. The reason is that a DLL used in the system has used log4cxx. We also want to use log4cxx during the development process, but we don't want to write the logs in the DLL to the same file. The problem arises. How can we print the logs to different files, the DLL adopts the getrootlogger method.
The article in this URL is good, the solution mainly refer to this article: http://www.open-open.com/doc/v
block, we read the code, found that the original log4j configuration file is read here, And he is first to find log4j.xml, if not found to find Log4j.properteis.
In fact, there is a solution to this problem is to log4j the source code, the form of the project into the Eclipse/idea, and then the global search log4j.properties or Log4j.xml. Why do you want to search these 2 file names. Because the log4j default configuration file name is these 2, then he in the program, there will certainly be a
appender specifies a layout for formatting.
1. Define the configuration file log4j. Properties1.Log4j. Recorder name = [level], storage device name 1, storage device name 2 ,...Levels of priority from high to low are: Off, fatal, error, warn, info, debug, allWe recommend that you use only four levels of log4j. The priority ranges from high to low: error, warn, info, and debug.Only log information with a higher priority or equal to the set level is forwarded. For example, if it is defined as inf
the dynamic link library of log4cxx (lib4cxx. dll );
Note: The compilation path cannot contain folders with spaces. Because this is not allowed in Unix systems, you are advised to select a root directory for compilation during compilation.
5. Configure the environment
Create a new project and set the include path and static library path (tool-> Option-> directory) of the VC compiling environment to include the preceding three files.Note:In addition, you must add ", Unicode" to "Project-> s
the log system is a very popular mode in the Java field and is widely used. The combination of the two results: simple + powerful.
Commons-logging provides simple and unified interfaces without additional configuration;
Log4j features are comprehensive and powerful;
Commons-logging only packs log4j (including other log implementations of course) layer by layer, and the specific log output is forwarded internally to log4j behind it for processing; although log4j has done everything, it has never
("************************************* *********");
}
}
}
It can be seen that the core of the program is to call the getById method of TeacherMapper.
1. If the content of log4j. properties is as follows:
# Global log Configuration
Log4j. rootLogger = DEBUG, stdout
# MyBatis log-level configuration. Configure com. abc. mapper
# The Log Level of all classes under the package
Log4j.logger.com. abc. mapper = DEBUG
# Use the follow
Log4j configuration file is used to set the recorder level, storage device, and layout. It can be connected to key = value format settings or XML format settings. Through configuration, you can create a log4j runtime environment.
1. Configuration FileThe basic format of the log4j configuration file is as follows:# Configure the root Logger
Log4j. rootlogger = [level], appendername1, appendername2 ,...
# Configure the appender of the log output destin
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.