Log4j显示包名称 [英] Log4j show package name

查看:548
本文介绍了Log4j显示包名称的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我现在对于我的ConversionPattern:

Right now for my ConversionPattern I have:

log4j.appender.A1.layout.ConversionPattern=%d{yyyy MMM dd HH:mm:ss,SSS} %5p [%t] (%F:%L) - %m%n

我想要做的还包括类的完整包名(%F:%L)但我找不到在文档中执行此操作的任何配置。我知道这会慢一点,但它只适用于调试而不是系统何时投入生产。

What I'd like to do is also include the full package name with the class (%F:%L) but I can't find any config to do so in the docs. I do understand that this will be slower, but it's only for debugging and not when the system will be in production.

推荐答案

也许我只是误解了你,但是%C会输出你的课程。

Maybe I just misunderstand you, but %C will output your class with package.

来自你的参考文档:

%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.

例如,对于类名
org.apache .xyz.SomeClass,
模式%C {1}将输出SomeClass。

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.

更新:
在许多情况下,您也可以使用%c,如果您的类别是您的类名,它也将打印出包含完整的类。例如,在初始化日志时你做这样的事情:

Update: In many cases you can use %c also, which will print out the full class with package also, if your category is your class-name. For example when your doing stuff like this when initializing your Log:

private static final Log LOG = LogFactory.getLog(MyClazz.class);

使用%c并不慢。

这篇关于Log4j显示包名称的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆