gpt4 book ai didi

java 日志属性 : Log a certain class to a specific log file

转载 作者:行者123 更新时间:2023-11-30 06:30:07 25 4
gpt4 key购买 nike

我使用 java.util.logging 的属性文件,并希望记录包下的所有类:

aaa.bbb.ccc.*

正常的方式(即信息,很好,更好)但是类

aaa.bbb.ccc.ddd.MyClass

在它自己的日志文件“My Class.log”中,级别更精细。

配置只能通过属性文件完成。这会是什么样子?

我尝试了各种方法(例如不同的处理程序)但没有成功:写入两个日志文件从来没有用过。

为了使问题更具体 - 我尝试的配置:

handler.performance.class=com.logging.handler.FileHandler
handler.performance.file=${LOGGING_ROOT}/performance.log
handler.performance.level=FINE

handler.fine.class=com.logging.handler.FileHandler
handler.fine.file=${LOGGING_ROOT}/finer.log
handler.fine.level=FINE

handler.async.class=com.logging.handler.AsyncBufferHandler
handler.async.level=ALL
handler.async.targets=fine

handler.asyncperf.class=com.logging.handler.AsyncBufferHandler
handler.asyncperf.level=ALL
handler.asyncperf.targets=performance

com.myapp.handlers=async,console
com.myapp.useParentHandlers=false

com.myapp.common.logging.handlers=asyncperf
com.myapp.common.logging.useParentHandlers=false

我要记录到这个单独的性能日志的类位于 com.myapp.common.logging... 下

最佳答案

找到解决方案 - 这是一个错误的初始化:

记录器应该初始化为:

Logger.getLogger(MyClass.class.getName())

然后是配置:

com.myapp.common.logging.MyClass.handlers=asyncperf
com.myapp.common.logging.MyClass.useParentHandlers=false

根据需要在指定的单独文件中记录此类的所有日志消息!

关于java 日志属性 : Log a certain class to a specific log file,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10830847/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com