`
justin.xxt
  • 浏览: 26900 次
  • 性别: Icon_minigender_1
  • 来自: 深圳
社区版块
存档分类
最新评论

log4j的ConversionPattern的参数详解

阅读更多

下面表格是从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详解** 日志框架在软件开发中扮演着至关重要的角色,它提供了记录应用程序运行过程中的各种事件的功能,便于调试、监控和问题排查。Log4j是Apache组织开发的一个开源的日志记录工具,广泛应用于Java...

    SpringBoot框架配置log4j和log4j2的配置代码

    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 入门到详解[推荐].pdf

    ### Log4j从入门到详解知识点汇总 #### 1. Log4j简介 Log4j是Apache的一个开源项目,主要用于实现日志记录功能。通过使用Log4j,开发者可以非常方便地控制日志信息的输出目的地(如控制台、文件等)、每条日志的...

    log4j使用教程(详解)

    **日志框架Log4j详解** 在Java编程中,日志记录是不可或缺的一部分,它用于追踪应用程序的运行状态,帮助开发者在出现问题时定位错误、调试程序。Log4j是一款广泛使用的开源日志框架,由Apache软件基金会开发。本文...

    log4j.properties配置详解

    ### Log4j.properties配置详解 #### 一、Log4j配置文件基本概念 Log4j是一种广泛应用于Java应用程序的日志框架,它可以帮助开发者轻松管理应用程序的日志记录过程。Log4j支持多种配置方式,其中.properties文件...

    SSM整合中的Log4j日志的配置详情

    Log4j 在 SSM 整合中的配置详解 Log4j 是一个功能强大且广泛使用的日志记录工具,特别是在 SSM(Spring、Spring MVC、Mybatis)整合项目中,合理地配置 Log4j 对项目的日志记录和输出至关重要。本文将详细介绍 SSM...

    log4j入门、详解.pdf

    ### Log4j 入门与详解 #### 一、Log4j简介 Log4j是Apache组织提供的一个开源日志框架,它可以帮助开发者轻松地在应用程序中实现日志记录功能。传统的日志记录方式通常是在代码中直接使用`System.out.println()`等...

    Log4j写入数据库详解

    ### Log4j写入数据库详解 #### 一、Log4j简介 Log4j是一个流行的开源日志框架,由Apache Software Foundation开发维护。它提供了一种灵活的方式来控制日志的生成,使得日志的级别、格式以及输出目的地都可以在运行...

    log4j常用配置详解

    ### log4j常用配置详解 ### #### 一、log4j.properties 配置解析 #### 在Java开发领域中,log4j是一款非常流行的日志框架,它提供了丰富的配置选项来满足不同场景下的日志记录需求。本文将详细介绍两种常见的log4j...

    常用log4j的配置详解

    ### 常用log4j配置详解 #### log4j简介 Log4j是一个开源的日志框架,由Apache Software Foundation开发。它允许开发者通过简单的配置文件来定义日志的输出等级、输出目的地以及日志信息的格式等。这极大地提高了...

    log4j.properties详解与例子

    例如,`log4j.appender.A1.layout=org.apache.log4j.PatternLayout`,然后可以通过`conversionPattern`设定输出格式,如`%d{ABSOLUTE} %5p %c{1}:%L - %m%n`,这将输出日期、优先级、类名、行号和日志消息。...

    log4j日志配置以及配置文件详解

    本文将深入探讨log4j的配置以及配置文件的详解。** 首先,我们要理解什么是`log4j.properties`文件。这是log4j框架的配置文件,使用Java Properties格式,用于定义日志输出的行为。主要包括以下几个核心部分: 1. ...

    log4j_jar包跟教程说明

    **日志框架Log4j详解** 在Java编程中,日志记录是一项不可或缺的功能,它能够帮助开发者追踪程序运行状态,定位错误,优化性能。Log4j是Apache组织提供的一款广泛使用的开源日志框架,适用于各种Java应用程序。本...

    log4j.properties 的使用详解(含log4j.properties)

    《log4j.properties 使用详解》 在Java开发中,日志记录是一项不可或缺的工作,它能够帮助开发者追踪程序运行状态,定位错误,优化性能。而log4j作为一款强大的日志框架,广泛应用于各种Java项目中。本文将详细介绍...

    log4j-1.2.17的jar包以及依赖包,还有一份log4j的配置文件,输出到控制台和文件夹两种配置

    **日志框架Log4j详解** Log4j是Apache组织提供的一款开源的日志记录框架,广泛应用于Java应用程序中。在给定的压缩包文件中,包含的是Log4j的1.2.17版本,这是一个相对较为老旧但仍然被许多项目使用的版本。此版本...

    tomcat下的log4j日志配置

    ### Tomcat 下的 Log4j 日志配置详解 在日常的 Web 开发中,日志记录对于调试问题、监控系统状态以及后期维护来说至关重要。在使用 Apache Tomcat 作为服务器时,合理配置日志框架(如 Log4j)能够极大地提高开发...

    log4j从入门到详解

    ### log4j从入门到详解 #### 1. Log4j简介 Log4j是一款由Apache组织提供的开源日志组件,被广泛应用于Java应用程序中。它可以帮助开发者在应用程序中记录日志信息,这对于调试程序、追踪错误以及进行系统监控等...

    log4j配置详解 新手入门教程

    ### Log4j配置详解 #### 一、Log4j简介 Log4j是Apache的一个开源项目,用以实现日志功能。它通过简单的API提供强大的日志记录功能,并且允许用户自定义配置来控制日志的输出级别、输出格式、输出目的地等。Log4j在...

Global site tag (gtag.js) - Google Analytics