使用slf4j实现Custom Logger [英] Implement Custom Logger with slf4j

查看:308
本文介绍了使用slf4j实现Custom Logger的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想实现一个自定义记录器,它将所有日志条目记录到数据库中。
目前我的应用程序以这种方式记录(slf4j和log4j绑定):

I want to implement a Custom logger which logs all log entries to a Database. Currently my app logs this way (slf4j and log4j binding):

private static final Logger logger = LoggerFactory.getLogger( MyClass.class );

我不知道如何继续。
我的想法是通过实现 > org.slf4j.Logger界面

I'm not sure how to proceed. My Idea is to implement a Custom Logging binding through implementing the org.slf4j.Logger Interface

接下来的步骤是什么?
我的目标是不更改当前代码

What would be the next steps? My target is to not change the current code

我考虑的链接:

  • Java custom logger: logging standards or/and best practices
  • http://www.slf4j.org/manual.html

推荐答案

它应该相当容易。你需要实现自己的 Logger LoggerFactory 。您根本不需要更改现有代码。

it should be fairly easy. you'll need to implement your own Logger and LoggerFactory. you will not have to change existing code at all.

执行此操作后,您需要实现 StaticLoggerBinder to返回您的记录器工厂和类名。如果您下载了slf4j zip文件,那么您也可以获得所有实现的源代码,只需查看slf4j-log4j中的StaticLoggerBinder即可。

after doing that you'll need to implement StaticLoggerBinder to return your logger factory and class name. if you download the slf4j zip file then you get the source for all the implementations too, just have a look at the StaticLoggerBinder in slf4j-log4j for an example.

有一个请查看此链接以获取详细信息: http://www.slf4j.org/faq.html#slf4j_compatible

have a look at this link for details : http://www.slf4j.org/faq.html#slf4j_compatible

这篇关于使用slf4j实现Custom Logger的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆