Log4j: Difference between revisions
| (12 intermediate revisions by 2 users not shown) | |||
| Line 7: | Line 7: | ||
* layouts. | * layouts. | ||
==Logger== | ==Logger/Category== | ||
Loggers are named entities. Logger names are case-sensitive and they follow the hierarchical naming rule. 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. | Loggers are named entities and sub classes of category. Logger names are case-sensitive and they follow the hierarchical naming rule. 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. Eine Referenz auf die Instanz des Root-Loggers kann mit der statischen Funktion | ||
Logger.getLooger("<NAME>"); | |||
geholt werden. | |||
The '''root logger''' resides at the top of the logger hierarchy. It is exceptional in two ways: | The '''root logger''' resides at the top of the logger hierarchy. It is exceptional in two ways: | ||
#it always exists, | #it always exists, | ||
#it cannot be retrieved by name, but by Logger.getRootLogger(). | #it cannot be retrieved by name, but by Logger.getRootLogger(). | ||
==Priority== | ==Priority== | ||
| Line 26: | Line 25: | ||
* FATAL | * FATAL | ||
Priority objects have both a string name and an integer value. The name is simply a mnemonic label for the priority. The integer value defines a relative order amongst priorities. The Level class extends the Priority class to be conform with java.util.logging. For the standard levels, we have DEBUG < INFO < WARN < ERROR < FATAL. | Priority objects have both a string name and an integer value. The name is simply a mnemonic label for the priority. The integer value defines a relative order amongst priorities. The Level class extends the Priority class to be conform with java.util.logging. For the standard levels, we have DEBUG < INFO < WARN < ERROR < FATAL. | ||
==Layout== | |||
The layout is defined in a pattern prefixed by % and a following letter code: | |||
* c: category | |||
* C: class name | |||
* d{<Format>}: date e.g. %d{HH:mm:ss,SSS} | |||
* E: exception stack | |||
* F: file name | |||
* l: location | |||
* L: line number | |||
* m: message | |||
* M: method name | |||
* p: log level (ERR, INFO, ...) | |||
* s: message | |||
* t: name of the thread | |||
==Logging== | |||
Das Loggen von Meldungen erfolgt über so genannte "Printing-Methods". Folgende Methoden sind verfügbar: | |||
logger.[debug()|info()|warn()|error()fatal()|log()|trace()]; | |||
=Configuration= | =Configuration= | ||
Latest revision as of 23:51, 15 March 2021
Concepts[edit]
Log4j has teh following fundamental objects:
- logger
- categories,
- priorities (levels),
- appenders and
- layouts.
Logger/Category[edit]
Loggers are named entities and sub classes of category. Logger names are case-sensitive and they follow the hierarchical naming rule. 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. Eine Referenz auf die Instanz des Root-Loggers kann mit der statischen Funktion
Logger.getLooger("<NAME>");
geholt werden.
The root logger resides at the top of the logger hierarchy. It is exceptional in two ways:
- it always exists,
- it cannot be retrieved by name, but by Logger.getRootLogger().
Priority[edit]
Loggers may be assigned levels. The set of possible levels, that is:
- TRACE
- DEBUG
- INFO
- WARN
- ERROR
- FATAL
Priority objects have both a string name and an integer value. The name is simply a mnemonic label for the priority. The integer value defines a relative order amongst priorities. The Level class extends the Priority class to be conform with java.util.logging. For the standard levels, we have DEBUG < INFO < WARN < ERROR < FATAL.
Layout[edit]
The layout is defined in a pattern prefixed by % and a following letter code:
- c: category
- C: class name
- d{<Format>}: date e.g. %d{HH:mm:ss,SSS}
- E: exception stack
- F: file name
- l: location
- L: line number
- m: message
- M: method name
- p: log level (ERR, INFO, ...)
- s: message
- t: name of the thread
Logging[edit]
Das Loggen von Meldungen erfolgt über so genannte "Printing-Methods". Folgende Methoden sind verfügbar:
logger.[debug()|info()|warn()|error()fatal()|log()|trace()];
Configuration[edit]
Properties can be defined by a properties file or by an XML file. The xml configuration class offers more flexibility and the benefits, and drawbacks, of an XML based configuration.
Logging Level are:
- ALL
- DEBUG
- ERROR
- FATAL
- INFO
- OFF
- TRACE
- WARN