log4j 用于独立的 java 项目

发布于 2024-09-12 04:46:36 字数 137 浏览 0 评论 0原文

我正在考虑将 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

沒落の蓅哖 2024-09-19 04:46:36

是的,这是可能的,我们一直这样做。您只需要在类路径上有一个 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.

恋竹姑娘 2024-09-19 04:46:36

是的,这是可能的。

如果您打算创建 jar 文件。

  • 确保在 jar 文件的 classes 文件夹中找到 log4j.properties。
  • 确保您的 log4j jar 包含在您的类路径中。

享受!

Yes it's possible.

If you're planning to create a jar file.

  • Make sure that your log4j.properties is found in your classes folder in jar file.
  • Make sure that your log4j jar is included in your classpath.

Enjoy!

尸血腥色 2024-09-19 04:46:36

绝对可以在独立项目中使用 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).

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文