[color=darkred][b][size=large]Loggers, Appenders and Layouts[/size][/b][/color]
Log4j has three main components: loggers, appenders and layouts. These three types of components work together to enable developers to log messages according to message type and level, and to control at runtime how these messages are formatted and where they are reported.
Logger用来定义level级别和所处的层(hierarchy);Apender用来定义将这些Log messages存放在哪里;Layout用来定义存放log messages的格式;
了解定义
[color=darkred][b]Logger hierarchy[/b][/color]
Named Hierarchy
A logger is said to be an ancestor of another logger if its name followed by a dot is a prefix of the descendant logger name. A logger is said to be a parent of a child logger if there are no ancestors between itself and the descendant logger.
For example, the logger named "com.foo" is a parent of the logger named "com.foo.Bar". Similarly, "java" is a parent of "java.util" and an ancestor of "java.util.Vector". This naming scheme should be familiar to most developers.
一个logger对象可以有parent和ancestor,比如
Logger logger1 = Logger.getLogger("com");
Logger logger2 = Logger.getLogger("com.foo");
Logger logger3 = Logger.getLogger("com.foo.bar");
logger1是logger2的parent,是logger3的ancestor;
The root logger resides at the top of the logger hierarchy. It is exceptional in two ways:
(这里没明白)
1. it always exists,
2. it cannot be retrieved by name.
Invoking the class static Logger.getRootLogger method retrieves it. All other loggers are instantiated and retrieved with the class static Logger.getLogger method.
//root logger有待继续理解,不甚了解
http://logging.apache.org/log4j/1.2/manual.html
Log4j has three main components: loggers, appenders and layouts. These three types of components work together to enable developers to log messages according to message type and level, and to control at runtime how these messages are formatted and where they are reported.
Logger用来定义level级别和所处的层(hierarchy);Apender用来定义将这些Log messages存放在哪里;Layout用来定义存放log messages的格式;
了解定义
[color=darkred][b]Logger hierarchy[/b][/color]
Named Hierarchy
A logger is said to be an ancestor of another logger if its name followed by a dot is a prefix of the descendant logger name. A logger is said to be a parent of a child logger if there are no ancestors between itself and the descendant logger.
For example, the logger named "com.foo" is a parent of the logger named "com.foo.Bar". Similarly, "java" is a parent of "java.util" and an ancestor of "java.util.Vector". This naming scheme should be familiar to most developers.
一个logger对象可以有parent和ancestor,比如
Logger logger1 = Logger.getLogger("com");
Logger logger2 = Logger.getLogger("com.foo");
Logger logger3 = Logger.getLogger("com.foo.bar");
logger1是logger2的parent,是logger3的ancestor;
The root logger resides at the top of the logger hierarchy. It is exceptional in two ways:
(这里没明白)
1. it always exists,
2. it cannot be retrieved by name.
Invoking the class static Logger.getRootLogger method retrieves it. All other loggers are instantiated and retrieved with the class static Logger.getLogger method.
//root logger有待继续理解,不甚了解
package org.apache.log4j;
public class Logger {
// Creation & retrieval methods:
public static Logger getRootLogger();
public static Logger getLogger(String name);
// printing methods:
public void trace(Object message);
public void debug(Object message);
public void info(Object message);
public void warn(Object message);
public void error(Object message);
public void fatal(Object message);
// generic printing method:
public void log(Level l, Object message);
}
http://logging.apache.org/log4j/1.2/manual.html