下面表格是从org.apache.log4j.PatternLayout的javadoc中摘过来的,仅为了方便参考。
Conversion Character |
Effect |
c |
Used to
output the category of the logging event. The category conversion
specifier can be optionally followed by precision specifier, that is a
decimal constant in brackets.
If a precision specifier is given, then only the corresponding number
of right most components of the category name will be printed. By
default the category name is printed in full.
For example, for the category name "a.b.c" the pattern %c{2} will output "b.c". |
C |
Used to
output the fully qualified class name of the caller issuing the logging
request. This conversion specifier can be optionally followed by
precision specifier, that is a decimal constant in brackets.
If a precision specifier is given, then only the corresponding number
of right most components of the class name will be printed. By default
the class name is output in fully qualified form.
For example, for the class name "org.apache.xyz.SomeClass", the pattern %C{1} will output "SomeClass".
WARNING Generating the caller class information is slow. Thus, it's use
should be avoided unless execution speed is not an issue. |
d |
Used to
output the date of the logging event. The date conversion specifier may
be followed by a date format specifier enclosed between braces. For
example, %d{HH:mm:ss,SSS} or %d{dd MMM yyyy HH:mm:ss,SSS}. If no date
format specifier is given then ISO8601 format is assumed.
The date format specifier admits the same syntax as the time pattern
string of the SimpleDateFormat. Although part of the standard JDK, the
performance of SimpleDateFormat is quite poor.
For better results it is recommended to use the log4j date formatters.
These can be specified using one of the strings "ABSOLUTE", "DATE" and
"ISO8601" for specifying AbsoluteTimeDateFormat, DateTimeDateFormat and
respectively ISO8601DateFormat. For example, %d{ISO8601} or
%d{ABSOLUTE}.
These dedicated date formatters perform significantly better than SimpleDateFormat. |
F |
Used to output the file name where the logging request was issued.
WARNING Generating caller location information is extremely slow. It's
use should be avoided unless execution speed is not an issue. |
I |
Used to output location information of the caller which generated the logging event.
The location information depends on the JVM implementation but usually
consists of the fully qualified name of the calling method followed by
the callers source the file name and line number between parentheses.
The location information can be very useful. However, it's generation
is extremely slow. It's use should be avoided unless execution speed is
not an issue. |
L |
Used to output the line number from where the logging request was issued.
WARNING Generating caller location information is extremely slow. It's
use should be avoided unless execution speed is not an issue. |
m |
Used to output the application supplied message associated with the logging event. |
M |
Used to output the method name where the logging request was issued.
WARNING Generating caller location information is extremely slow. It's
use should be avoided unless execution speed is not an issue. |
n |
Outputs the platform dependent line separator character or characters.
This conversion character offers practically the same performance as
using non-portable line separator strings such as "\n", or "\r\n".
Thus, it is the preferred way of specifying a line separator. |
p |
Used to output the priority of the logging event. |
r |
Used to output the number of milliseconds elapsed from the construction of the layout until the creation of the logging event. |
t |
Used to output the name of the thread that generated the logging event. |
x |
Used to output the NDC (nested diagnostic context) associated with the thread that generated the logging event. |
X |
Used to
output the MDC (mapped diagnostic context) associated with the thread
that generated the logging event. The X conversion character must be
followed by the key for the map placed between braces, as in
%X{clientNumber} where clientNumber is the key. The value in the MDC
corresponding to the key will be output.
See MDC class for more details. |
% |
The sequence %% outputs a single percent sign. |
分享到:
相关推荐
**日志框架Log4j详解** 日志框架在软件开发中扮演着至关重要的角色,它提供了记录应用程序运行过程中的各种事件的功能,便于调试、监控和问题排查。Log4j是Apache组织开发的一个开源的日志记录工具,广泛应用于Java...
log4j.appender.stdout.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss} %-5p %c{1}:%L - %m%n log4j.appender.file=org.apache.log4j.DailyRollingFileAppender log4j.appender.file.File=app.log log4j....
### Log4j从入门到详解知识点汇总 #### 1. Log4j简介 Log4j是Apache的一个开源项目,主要用于实现日志记录功能。通过使用Log4j,开发者可以非常方便地控制日志信息的输出目的地(如控制台、文件等)、每条日志的...
**日志框架Log4j详解** 在Java编程中,日志记录是不可或缺的一部分,它用于追踪应用程序的运行状态,帮助开发者在出现问题时定位错误、调试程序。Log4j是一款广泛使用的开源日志框架,由Apache软件基金会开发。本文...
### Log4j.properties配置详解 #### 一、Log4j配置文件基本概念 Log4j是一种广泛应用于Java应用程序的日志框架,它可以帮助开发者轻松管理应用程序的日志记录过程。Log4j支持多种配置方式,其中.properties文件...
Log4j 在 SSM 整合中的配置详解 Log4j 是一个功能强大且广泛使用的日志记录工具,特别是在 SSM(Spring、Spring MVC、Mybatis)整合项目中,合理地配置 Log4j 对项目的日志记录和输出至关重要。本文将详细介绍 SSM...
### Log4j 入门与详解 #### 一、Log4j简介 Log4j是Apache组织提供的一个开源日志框架,它可以帮助开发者轻松地在应用程序中实现日志记录功能。传统的日志记录方式通常是在代码中直接使用`System.out.println()`等...
### Log4j写入数据库详解 #### 一、Log4j简介 Log4j是一个流行的开源日志框架,由Apache Software Foundation开发维护。它提供了一种灵活的方式来控制日志的生成,使得日志的级别、格式以及输出目的地都可以在运行...
### log4j常用配置详解 ### #### 一、log4j.properties 配置解析 #### 在Java开发领域中,log4j是一款非常流行的日志框架,它提供了丰富的配置选项来满足不同场景下的日志记录需求。本文将详细介绍两种常见的log4j...
### 常用log4j配置详解 #### log4j简介 Log4j是一个开源的日志框架,由Apache Software Foundation开发。它允许开发者通过简单的配置文件来定义日志的输出等级、输出目的地以及日志信息的格式等。这极大地提高了...
例如,`log4j.appender.A1.layout=org.apache.log4j.PatternLayout`,然后可以通过`conversionPattern`设定输出格式,如`%d{ABSOLUTE} %5p %c{1}:%L - %m%n`,这将输出日期、优先级、类名、行号和日志消息。...
本文将深入探讨log4j的配置以及配置文件的详解。** 首先,我们要理解什么是`log4j.properties`文件。这是log4j框架的配置文件,使用Java Properties格式,用于定义日志输出的行为。主要包括以下几个核心部分: 1. ...
**日志框架Log4j详解** 在Java编程中,日志记录是一项不可或缺的功能,它能够帮助开发者追踪程序运行状态,定位错误,优化性能。Log4j是Apache组织提供的一款广泛使用的开源日志框架,适用于各种Java应用程序。本...
《log4j.properties 使用详解》 在Java开发中,日志记录是一项不可或缺的工作,它能够帮助开发者追踪程序运行状态,定位错误,优化性能。而log4j作为一款强大的日志框架,广泛应用于各种Java项目中。本文将详细介绍...
**日志框架Log4j详解** Log4j是Apache组织提供的一款开源的日志记录框架,广泛应用于Java应用程序中。在给定的压缩包文件中,包含的是Log4j的1.2.17版本,这是一个相对较为老旧但仍然被许多项目使用的版本。此版本...
### Tomcat 下的 Log4j 日志配置详解 在日常的 Web 开发中,日志记录对于调试问题、监控系统状态以及后期维护来说至关重要。在使用 Apache Tomcat 作为服务器时,合理配置日志框架(如 Log4j)能够极大地提高开发...
### log4j从入门到详解 #### 1. Log4j简介 Log4j是一款由Apache组织提供的开源日志组件,被广泛应用于Java应用程序中。它可以帮助开发者在应用程序中记录日志信息,这对于调试程序、追踪错误以及进行系统监控等...
### Log4j配置详解 #### 一、Log4j简介 Log4j是Apache的一个开源项目,用以实现日志功能。它通过简单的API提供强大的日志记录功能,并且允许用户自定义配置来控制日志的输出级别、输出格式、输出目的地等。Log4j在...