我使用 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/