This forum is now a read-only archive. All commenting, posting, registration services have been turned off. Those needing community support and/or wanting to ask questions should refer to the Tag/Forum map, and to http://spring.io/questions for a curated list of stackoverflow tags that Pivotal engineers, and the community, monitor.
No announcement yet.
how to initialize log4J system...Page Title Module
Configuring Log4J within Spring RichClient Application
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:
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