log4j 用于独立的 java 项目
我正在考虑将 log4j 用于我的独立 java 项目。 是否可以将它用于 java 项目(而不是网络应用程序)。
如果可能的话,我应该如何初始化属性文件以及应该在哪里初始化 我放置了属性文件(目录结构)。
任何帮助表示赞赏。
I was thinking to use log4j for my standalone java project.
Is it possible to use it for java project(not a web app).
If its possible then how should I be able to initialize the properties file and where should
I put the properties file(directory structure).
Any help is appreciated.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
是的,这是可能的,我们一直这样做。您只需要在类路径上有一个 log4j.properties 文件,这在大多数情况下意味着位于 jar 文件的基目录中。如果您希望拥有具有不同配置的多个属性文件,您可以在第一个日志记录语句之前的某个入口点创建一个属性配置器。
Yes, it is possible, we do it all the time. You just need a log4j.properties file on your classpath, which in most cases means in the base directory of your jar file. If you wish to have multiple properties files with differing configurations, you can create a properties configurator in some entry point before your first logging statement.
是的,这是可能的。
如果您打算创建 jar 文件。
classes
文件夹中找到 log4j.properties。享受!
Yes it's possible.
If you're planning to create a jar file.
classes
folder in jar file.Enjoy!
绝对可以在独立项目中使用 log4j。只需将您的类路径设置为包含 log4j jar 即可。至于属性文件,apache 文档应该说明 log4j 在哪里查找它(它可能也是可配置的)。
It's definitly possible to use log4j in a standalone project. Just set your classpath to include the log4j jar. As for the properties file, the apache documentation should say where to log4j looks for it (it's probably also configurable).