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.
|
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, 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 since the start of the application 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进行日志输出格式化以及设置日志文件名格式化,以满足公司的标准化需求。 首先,我们来看日志输出格式化。Log4j的核心在于其灵活性,可以通过自定义布局模板来控制日志输出的格式。最...
本文将深入讲解如何配置log4j以实现日志输出到控制台和文件,并提供相关代码实例和案例分析。** ### 一、Log4j简介 Log4j是Apache组织开发的一个开源项目,用于生成日志信息。它提供了灵活的配置方式,支持多种输出...
Log4j 的核心组件包括日志记录器(Logger)、日志输出目的地(Appender)和日志格式化器(Layout)。 二、配置 Log4j.properties 文件 在 SSM 整合项目中,配置 Log4j.properties 文件是必不可少的步骤。该文件...
2. **配置全局 Log4j 属性文件**:在任意位置创建 `log4j.properties` 文件,并设置全局的日志级别、输出格式及存储路径等。通常会将该文件放置在 Tomcat 的 `conf` 目录下。 ```properties log4j.rootLogger=...
- **Logger**: 日志记录器,是Log4j的核心组件,负责实际的日志输出。你可以为每个功能模块创建一个独立的Logger,以便区分日志来源。 - **Appender**: 输出目的地,用于定义日志信息被发送到哪里,如控制台、文件...
本文将深入探讨如何在Log4j中实现日志输出路径的动态配置。 首先,我们要理解Log4j的核心组件。Log4j主要包括三个关键部分:Logger(日志器)、Appender(输出器)和Layout(布局)。Logger负责生成日志事件,...
参照了几个网上大神配置,部分教程的描述有误,最终调试完成,可以实现kettle日志输出,测试版本...需要替换的文件为,Kettle的程序目录下data-integration-6.0\plugins\kettle5-log4j-plugin中有一个log4j.xml文件。
Log4j通过配置文件(通常是log4j.properties或log4j.xml)来设定日志输出级别、格式、目的地等参数。如果日志没有按预期输出,我们需要检查以下几个方面: 1. **配置文件**:确认配置文件是否正确包含在项目中,...
这个文件是Log4j日志配置的核心,用于定义日志的输出格式、日志文件的滚动规则等。 2. 配置DailyRollingFileAppender:通过定义一个DailyRollingFileAppender,可以使得日志文件按照日期进行滚动,每天生成一个新的...
这是log4j框架的配置文件,使用Java Properties格式,用于定义日志输出的行为。主要包括以下几个核心部分: 1. **Logger**: 定义日志级别,例如DEBUG、INFO、WARN、ERROR和FATAL。日志级别决定了哪些信息会被记录。...
Log4j的配置文件通常是`log4j.properties`或`log4j.xml`,在这里你可以设置不同级别的日志输出,例如DEBUG、INFO、WARN、ERROR等。 对于Ibatis,这是一个轻量级的持久层框架,它将SQL语句与Java代码分离,提供了...
Log4j提供了一个名为`org.apache.log4j.ConsoleAppender`的类,用于将日志输出到控制台,我们可以通过自定义Filter或者继承现有Appender来实现这个功能。 下面是一个简单的示例,展示如何在Log4j配置文件中设置...
首先,错误信息"log4j:WARN No appenders could be found for logger"表明Log4j找不到任何日志输出的目标,也就是没有设置日志appender。日志appender是Log4j用来定义日志输出目的地的组件,比如控制台、文件、邮件...
总结,通过以上步骤,你已成功配置了 MyBatis 使用 Log4j 来记录日志,同时将日志输出到后台控制台和文件,这有助于在开发和调试过程中追踪问题,提高代码的可维护性。记得根据实际需求调整日志级别和输出格式,以...
### Log4j日志管理系统简单使用说明 #### 一、Log4j简介 Log4j是一款流行的开源日志框架,由Apache软件基金会提供。它能够帮助开发者以灵活且高效的方式记录应用程序的日志信息。Log4j的核心组成部分包括:Loggers...
在“Log4j2实现不同线程不同级别日志输出到不同的文件中”这个主题中,我们将深入探讨如何利用Log4j2实现这一高级日志管理需求。 1. **日志级别**: - 在Log4j2中,日志级别包括DEBUG、INFO、WARN、ERROR、FATAL...
使用Log4j2的Layout组件定义日志输出格式。例如,我们可以使用PatternLayout,并自定义模式来指定哪些字段需要脱敏。例如,`%d{yyyy-MM-dd HH:mm:ss.SSS} [%t] %-5level %logger{36} - %msg%n` 是一个基本的日志...
实现分包日志输出的关键在于配置文件(通常是log4j.properties或log4j.xml)。在配置文件中,我们可以定义多个Logger,并通过设置它们的name属性为类的包名来关联不同的日志输出策略。以下是一个简单的配置示例: `...