log4j for standalone java project

折月煮酒 提交于 2021-02-19 06:27:05

问题


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.


回答1:


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.




回答2:


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!




回答3:


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).



来源:https://stackoverflow.com/questions/3364717/log4j-for-standalone-java-project

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!