Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Bundling log4j.properties in a library - bad style or what?

I came across a nice small web request framework for Java: Spark. The API looks nice and promising, but the library bundle itself is pretty strange. Leave alone the fact that it proposes using snapshot artifacts as dependencies. Leave alone the fact that it uses log4j for logging (libraries tend to use jcl or slf4j nowadays), and System.out.println sometimes. But it bundles its own log4j.properties in spark-xxx.jar. It took me an hour to investigate why my project would complain of log4j configuration when log4j.properties is definitely present in my classpath. -Dlog4j.debug=true gave the answer, log4j confessed that it had loaded log4j.properties from spark jar.

I wonder if this (being a library and using log4j and bundling log4j.properties) has some motivation, or if it is just lame.

like image 651
zamza Avatar asked Aug 06 '11 03:08

zamza


People also ask

Where should log4j properties be placed?

The file is named log4j. properties and is located in the $DGRAPH_HOME/dgraph-hdfs-agent/lib directory. The file defines the ROLLINGFILE appenders for the root logger and also sets the log level for the file. The level of the root logger is defined as INFO and attaches the ROLLINGFILE appender to it.

Does log4j need a properties file?

It's optional if the file name is log4j. properties and it's in the project classpath. We have to configure it before using the logger. Here is a simple program showing how to configure and use log4j logging.

How log4j properties file is read?

The log4j properties file contains the entire runtime configuration used by log4j. This file will contain log4j appenders information, log level information and output file names for file appenders. By default, the LogManager searches for a file named log4j. properties in the CLASSPATH.


1 Answers

It is bad style to bundle a log4j.properties with a library.

With spark you could argue that it is closer to an app server (like tomcat) in which case it could configure logging.

I would say the test is that whoever controls the start(.sh|.bat) script should configure logging, and that log4j config files should almost never be in a jar.

like image 119
sbridges Avatar answered Nov 02 '22 00:11

sbridges