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

标签 java logging properties java.util.logging

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

相关文章:

logging - InfluxDB不断追加到/var/log/syslog

java - 使用外部属性的 JBoss 5.1 数据源配置

c# - 从对象中删除 null 属性

c++ - QMetaObject::indexOfMethod 返回的索引到底是什么?

java - IntelliJ : How to import a folder of . java 文件作为库?

java - 为客户端 jar 中的方法定义变量

c# - 是否可以在 C#/.Net 中将消息记录到 cmd.exe?

logging - 即使数据在Elasticsearch中,Graylog2 Web界面也不会显示日志/消息

java - URL获取参数的问题

java - 需要 Spring Boot CLIENT_PLUGIN_AUTH