问题
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