作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我使用 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/
我是一名优秀的程序员,十分优秀!