Announcement Announcement Module
Collapse
No announcement yet.
how to initialize log4J system... Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • how to initialize log4J system...

    How log4J system is initialized?
    whwnever i try to run my application it prompts me to initialize the log4J system properly.

  • #2
    Configuring Log4J within Spring RichClient Application

    Hi,

    you have two options:
    - do it programatically in main(), before you even create the ApplicationLauncher
    - do it the usual way, i.e. provide a log4j.xml in the root of the classpath.

    Log4J has an "default initialisation sequence" which is triggered by loading org.apache.log4j.LogManager . Normally, you don't need to to this manually, just issue the first Logger.getLogger("xyz") and this initialisation is triggered. And because already the Spring RichClient framework code uses logging (via the commons.logging facade), you need to have the configuration in place before starting your app. See http://logging.apache.org/log4j/1.2/manual.html (look for "Default Initialization Procedure").

    Normally, you should prefer the "usual way" via a log4j configuration file. But doing the configuration hard wired (programmatically) can be helpful in the following situations:
    - you want to switch off Logging altogether
    - you just want to provide a very basic config and won't ever want to configure it in more detail
    - you want to capture all log messages and forward them to some server process (highly recommended if you write a distributed client-server app with many clients)

    Hint: the most simple thing is to silence log4j altogether. You can do it as follows:

    System.setProperty("log4j.defaultInitOverride","tr ue");
    LogManager.resetConfiguration();
    LogManager.getRootLogger().addAppender(new NullAppender());

    for very simplistic logging, instead of a NullAppender, you add a ConsoleAppender or a simple file appender. But my recommendation is: look in the log4j doku and learn how to configure it, that's very usefull knowledge

    cheers
    Hermann V.

    Comment

    Working...
    X