log4j 和 java.util.logging 有什么区别
哪个最适合获取登录其帐户的用户的日志文件?用一个小例子解释一下...谢谢您的时间...
Which is best for getting the log files of user logged in his account? Explain with a small example... Thanks for your time...
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
Log4j 是 Java 的事实上的标准日志库。
Java.util.logging 是 Java 中内置的日志记录机制,但这并不意味着它是最好的...
使用 Log4j 及其 MDC。这样,您可以轻松地记录不同的用户帐户,如下所示:
这样,如果日志记录配置正确,您将在日志输出中看到如下内容:
这适用于多用户环境中的每个用户。
注意:如果您要开始一个新项目,我建议使用 slf4j 和 登录。这种组合比 log4j 或 java.util.logging 更强大。
我已经使用这个组合有一段时间了,它确实得到了丰厚的回报。除其他外,对于消除错误和审核用户交互非常有用。
Log4j is a defacto standard logging library for Java.
Java.util.logging is a built in logging mechanism in Java, but that doesn't make it the greatest...
Use Log4j and its MDC. This way, you can easily log different user accounts like this:
This way, if logging is configured correctly, in your log output you will see something like this:
and this will work for every user in a multi user environment.
Note: if you're starting a new project, I'd suggest using slf4j and Logback. This combination is even more powerful than log4j or java.util.logging.
I have been using this combination for some time and it has really paid off handsomely. Very useful for bug squashing and auditing user interaction, among other things.