java 如何实现/使用 log4j?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/3495443/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-30 02:06:10  来源:igfitidea点击:

How to implement/use log4j?

javalogginglog4j

提问by Caladain

I am soon going to use log4j class using Java, for a project, to create logs. But i dont think i know or have any slightest idea about it. Hope someone enlightens me over this, but, trivial issue.

我很快将使用 Java 的 log4j 类,为一个项目创建日志。但我不认为我知道或有任何想法。希望有人能在这个问题上启发我,但是,微不足道的问题。

回答by Caladain

Log4j basically takes any statement you want to output, lets you assign a "severity" level to it (warning, error, critical, etc) and logs it out in a variety of ways. (to a file, to a byte stream, etc. there are lots of appender options available.);

Log4j 基本上接受您想要输出的任何语句,让您为其分配“严重性”级别(警告、错误、严重等)并以各种方式将其注销。(对于文件,字节流等,有很多可用的附加程序选项。);

Here's a short blurb introduction to log4j.
http://www.developer.com/open/article.php/3097221/Logging-with-log4jmdashAn-Efficient-Way-to-Log-Java-Applications.htm

这是对 log4j 的简短介绍。
http://www.developer.com/open/article.php/3097221/Logging-with-log4jmdashAn-Efficient-Way-to-Log-Java-Applications.htm

Here's a short tutorial:
http://veerasundar.com/blog/2009/07/log4j-tutorial-adding-log4j-logging-to-your-project/

这是一个简短的教程:http:
//veerasundar.com/blog/2009/07/log4j-tutorial-adding-log4j-logging-to-your-project/

回答by Joelio

Log4j is very easy to use. Try the manual.

Log4j 非常易于使用。试试手册

Also lots of people use commonslogging to wrapper log4j, if you are sure you want to use log4j for the long term then use it directly.

还有很多人使用公共日志来包装 log4j,如果您确定要长期使用 log4j,则直接使用它。

You should also get agreement within your development team what logging levels mean what to your org, for example TRACE & DEBUG are pretty easy. But often people dont have standards as when to use INFO vs WARN vs ERROR. Also what should happen when a log entry of a certain level happens. I like to look at it from the operators point of view, when you see a log level of "FATAL" what do you do? or of "ERROR" etc.

您还应该在您的开发团队中达成一致,日志级别对您的组织意味着什么,例如 TRACE 和 DEBUG 非常简单。但是通常人们没有关于何时使用 INFO 与 WARN 与 ERROR 的标准。还有当某个级别的日志条目发生时会发生什么。我喜欢从运营商的角度来看,当你看到“FATAL”的日志级别时,你会怎么做?或“错误”等。