简体   繁体   English

使用log4j 1.x通过JDBC记录跟踪

[英]Logging traces over JDBC with log4j 1.x

We are using log4j 1.x as logging platform for quite some time now. 我们已经将log4j 1.x用作日志记录平台已有一段时间了。 Most of our applications are based on Spring Framework which also uses log4j 1.x. 我们的大多数应用程序都基于Spring Framework,该框架也使用log4j1.x。 Now we wish to write logs in database and we know (heard) that this (official) JDBC appender is bad. 现在我们希望在数据库中写入日志,并且我们知道(听说)这个(官方的)JDBC附加程序是错误的。 What would you suggest that we do for production environment? 您对我们的生产环境有何建议? Writing our own JDBC appender for log4j 1.x? 为log4j 1.x编写我们自己的JDBC附加程序?

Also that JDBC appender apparently does not log exception which is important for us. 同样,JDBC附加程序显然不会记录异常,这对我们很重要。

I know that Logback offers database appender, but I don't wish to switch - too much work. 我知道Logback提供了数据库附加程序,但是我不希望切换-太多的工作。 I also know that log4j 2 was rewritten and it's JDBC appender is OK, but it's not compatible with log4j 1.x even though it was compatibility API jar which has restrictions. 我也知道log4j 2已被重写,并且它的JDBC附加程序还可以,但是它与log4j 1.x不兼容,即使它是具有限制的兼容性API jar。

Maybe an option is to replace log4j with slf4j ( http://www.slf4j.org/ ) and add log4jdbc appender ( https://code.google.com/p/log4jdbc/ )? 也许可以选择用slf4j( http://www.slf4j.org/ )替换log4j并添加log4jdbc附加程序( https://code.google.com/p/log4jdbc/ )? Slf4j is a simple facade for log4j and other logging systems such as JCL or commons-logging where you don't need to change any line of code, you just need to add slf4j JARs into classpath and configure it. Slf4j是log4j和其他日志记录系统(如JCL或commons-logging)的简单外观,无需更改任何代码行,只需将slf4j JAR添加到类路径中并对其进行配置。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM