选择日志文件

发布于 2024-07-17 05:35:36 字数 252 浏览 4 评论 0原文

我们的应用程序中有多个日志文件,例如数据库日志、网络日志、quartzlog。

/app/database 包下的文件中的任何日志都将转到数据库日志。 /app/offline 包下的文件中的任何日志都将转到quartzlog 日志中。

我们现在需要的是 - 希望将 /app/database 下的 java 文件之一的日志语句直接输出到quartzlog 而不是数据库日志。

我们如何在java文件中选择特定的日志文件?

We have multiple log files like database log, weblog, quartzlog in our application.

Any log from files under package /app/database will go to database log.
Any log from files under package /app/offline will go to quartzlog log.

What we need now is - want to direct the log staments from one of the java file under /app/database to be outputted to quartzlog instead of database log.

How can we select a particular log file in java file?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

池木 2024-07-24 05:35:36

您需要定义记录所需文件的适当附加程序。 阅读这个简短的介绍了解如何做到这一点。

然后在配置文件中,您可以指示来自特定包的所有消息进入选定的附加程序:

log4j.logger.my.package = DEBUG, myFileAppender

编辑:

我相信在 log4j 中只有包解析是可能的 - 您不能使用每个附加程序文件或方法。 您可以尝试通过在 log4j 之上添加额外的层或实现您自己的附加程序来解决此问题。

例如,不使用 log.debug 使用:

my.loggerproxy.log.debug(message);

如果您只需要从单个方法执行此操作,那么上面的内容就足够了。 只需指示记录器代理包记录在不同的文件中即可。

You need to define the appropriate appender that logs in the desired file. Read this short introduction to see how you can do it.

Then in the configuration file, you can instruct all messages from a specific package to go in the selected appender:

log4j.logger.my.package = DEBUG, myFileAppender

EDIT:

I believe that in log4j only package resolution is possible - you can't use an appender per file or method. You could try to work around this by adding an extra layer on top of log4j or implementing your own appender.

For example, instead of log.debug use:

my.loggerproxy.log.debug(message);

If you only need to do it from a single method, then the above will be enough. Just instruct the logger proxy package to be logged in a different file.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文