文档章节

log4j conversion pattern各格式含义

52iSilence7
 52iSilence7
发布于 2017/04/01 15:30
字数 796
阅读 26
收藏 0
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".

log名称

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, use should be avoided unless execution speed is not an issue.

class全限定名称,不建议使用,非常影响性能

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 AbsoluteTimeDateFormatDateTimeDateFormat 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 and should be avoided unless execution speed is not an issue.

文件名称 不建议使用

l 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, its generation is extremely slow and 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 and should be avoided unless execution speed is not an issue.

log所在行 不建议使用

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 and should be avoided unless execution speed is not an issue.

log所在方法名  不建议使用

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.

优先级 INFO,DEBUG,ERROR等

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.

NDC里面的信息

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.

MDC里面的信息

% The sequence %% outputs a single percent sign.

本文转载自:https://logging.apache.org/log4j/1.2/apidocs/org/apache/log4j/PatternLayout.html

52iSilence7

52iSilence7

粉丝 7
博文 109
码字总数 92129
作品 0
海淀
高级程序员
私信 提问
How to log in Spring with SLF4J and Logback

Introduction 1.1. Simple Logging Facade for Java(SL4J) The SLF4J serves as a simple facade or abstraction for various logging frameworks, such as java.util.logging, logback and ......

perfectspr
2014/11/19
1K
0
转一篇关于Log4j的介绍文章,很详细,留待以后查阅

1、 Log4j是什么? Log4j可以帮助调试(有时候debug是发挥不了作 用的)和分析,要下载和了解更详细的内容,还是访问其官方网站吧: http://jakarta.apache.org/log4j 。 2、Log4j的概念 Lo...

netwild
2013/05/02
0
0
《Apache Log4j 2 用户指南》简介

1.1 欢迎来到log4j 2! 1.1.1 简介 几乎每一个大型应用程序都包含自己的日志记录或跟踪API。根据这个规则,在1996年初,E.U. SEMPER项目决定编写自己的跟踪API。经过无数次的改进,多次转世和...

01/03
0
0
log4j 使用及配置分析记录

log4j是一个非常强大的log记录软件,下面我们就来看看在项目中如何使log4j。 ps:其配置文件有两种 log4j.properties 和log4j.xml 两种形式。xml更强大,功能更丰富 ,properties更简单易懂。...

北方攻城师
2015/04/12
212
0
Log4j 日志配置示例详解

日志是应用软件中不可缺少的部分,Apache的开源项目Log4j是一个功能强大的日志组件,提供方便的日志记录,具体请参考Log4j文档指南。 Log4j下载 在apache网站,可以免费下载到Log4j最新版本的...

长平狐
2013/01/06
172
0

没有更多内容

加载失败,请刷新页面

加载更多

读书笔记:深入理解ES6 (五)

第五章 解构:使数据访问更便捷 第1节 为什么使用解构功能?   在ES5中,开发者们从对象、数组中获取特定数据并赋值给变量,编写了很多看起来同质化的代码。例如: 1 let options = {2 ...

张森ZS
19分钟前
18
0
CentOS7 yum方式安装MySQL5.7

在CentOS中默认安装有MariaDB,这个是MySQL的分支,但为了需要,还是要在系统中安装MySQL,而且安装完成之后可以直接覆盖掉MariaDB。 1 下载并安装MySQL官方的 Yum Repository [root@localho...

roockee
28分钟前
14
0
Allegro三种自定义设置快捷键的方法

Allegro自定义设置快捷键的三种方法: 1、在Allegro PCB editor 命令窗口直接定义 2、通过修改用户变量env文件来设置快捷键 3、定义笔画为快捷键 1、在Allegro PCB editor 命令窗口直接定义 ...

demyar
32分钟前
15
0
如何做一张能让人眼前一亮的大屏?

作为在职场驰骋的社会人,提到数据可视化大家应该都不陌生了。数据可视化的作用也不用我多说,主要是利用图形化手段,更清晰直观地将数据展示。多层次、交互式的可视化分析能够方便决策者理解...

朕想上头条
33分钟前
8
0
TL138/1808/6748-EthEVM开发板硬件CPU、FLASH、RAM

TL138/1808/6748-EthEVM是广州创龙基于SOM-TL138/1808/6748核心板开发的一款开发板,具有三个网络接口。由于SOM-TL138/1808/6748核心板管脚兼容,所以此三个核心板共用同一个底板。开发板采用...

Tronlong创龙
37分钟前
11
0

没有更多内容

加载失败,请刷新页面

加载更多

返回顶部
顶部