logging-log4j-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Aidan Delaney <ai...@phoric.eu>
Subject Initializing log4j in a library
Date Wed, 18 Jul 2012 15:00:39 GMT
Dear all,
I have a bunch of loosely related class files that I distrubute in a single jar.  So, for
instance I have Foo.java and Bar.java, where there is not top-level init() for the library.
 I also want to use log4j to replace the antiquated not-quite-logging system that is in this
code.  I'm wondering what's the best-practice way to do this.

>From what I can see, it's best to create a ProjectLogger with a static initialiser

public class ProjectLogger {
  static {
    Logger logger = Logger.getLogger(ProjectLogger.class.getName());

  static void doInit() {}

Then importing this into each of Foo.java and Bar.java.


import ProjectLogger;

pubilc class Foo {
  static {
     Logger logger = Logger.getLogger(Foo.class.getName());


and so forth.

This is not pretty as you need the ProjectLogger.init() in each file.  However, does this
concur with best practice?  Or is it a bit insane?


To unsubscribe, e-mail: log4j-user-unsubscribe@logging.apache.org
For additional commands, e-mail: log4j-user-help@logging.apache.org

View raw message