log4j示例配置文件(属性文件)
开始使用 log4j 配置的最简单方法是什么?
What is the easiest way to get started with log4j configuration?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
开始使用 log4j 配置的最简单方法是什么?
What is the easiest way to get started with log4j configuration?
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
接受
或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
发布评论
评论(6)
将名为
log4j.properties
的文件放入类路径的根目录中:不需要其他任何东西。 Log4j 会发现它并自行配置。
Put a file named
log4j.properties
in the root of your classpath:Nothing else is needed. Log4j will discover it and configure itself.
最简单的方法是访问 apache 的 log4j 页面并阅读简短介绍 。他们有一个示例 log4j.configuration 可供复制和粘贴。
The absolute easiest way is to visit the log4j pages at apache and read the short introduction. They have a sample log4j.configuration ready to be copied and pasted.
值得阅读手册(冒着陈述显而易见的风险)。有大量的配置选项,一旦您学习并理解了哪些是可能的,那么您就可以实现一些非常强大的日志系统。
It's worth reading the manual (at the risk of stating the obvious). There are a ton of configuration options, and once you learn and understand what's possible, then you can implement some very powerful logging systems.
如果您偶然发现此问题并正在寻找 log4j2 的示例文件。我让它工作的方法是在基本“资源”目录中创建一个文件名 log4j2.xml (我使用的是 Maven,所以它是“src/main/resources”)
然后从手册中复制示例配置:
http://logging.apache.org/log4j/2.x/manual /configuration.html
这将为您提供一个漂亮的简单控制台记录器。我建议您将模式修改为您想要的外观,并将“根级别=”修改为更具包容性的内容。当然,请阅读手册以获取更强大的设置......
In case you stumble into this and are looking for a sample file for log4j2. The way I got it to work was to create a file names log4j2.xml in the base 'resources' directory (I'm using maven so that was 'src/main/resources')
Then copy the sample configuration from the manual:
http://logging.apache.org/log4j/2.x/manual/configuration.html
This will give you a nice simple console logger. I recommend you modify the pattern to how you want it to look and the 'Root level=' to something more inclusive. And of course, read the manual for more powerful settings...
除了其他一些答案之外,我还会添加一个持久性附加程序,因为这是使用日志而不是控制台和调试器的最大优势;当无法实时运行应用程序代码或事件已经发生时。
!/"path"/"filename" 将写入文件系统的根目录。 “path”/“filename”将写入相对于类路径根的路径。
In addition to some other answers, I would add a persistence appender since that's the greatest advantage of using logs over consoles and debuggers; when one can't run through the application code in real-time or the event already occurred.
!/"path"/"filename" will write to root of filesystem. "path"/"filename" will write to path relative to classpath root.