Using Log4j in Equinox [message #96911] |
Mon, 10 September 2007 10:51  |
Eclipse User |
|
|
|
Hi,
I've created a bundle that intends to use log4j to log all the entries
in the framework. The idea is that a custom Listener will be registered
in LogReaderService and when it is called it will log to a file using
the capabilities of log4j.
The problem I'm having is that every time I start the bundle I get the
following error:
osgi> log4j:WARN No appenders could be found for logger (root).
log4j:WARN Please initialize the log4j system properly.
The class I'm using for listener is a very simple one, just to start
with a simple test:
package logger.file;
import org.apache.log4j.Logger;
import org.osgi.service.log.LogEntry;
import org.osgi.service.log.LogListener;
public class HUMSFileLogListener implements LogListener {
static Logger logger = Logger.getLogger(HUMSFileLogListener.class);
/*
* (non-Javadoc)
*
* @see
org.osgi.service.log.LogListener#logged(org.osgi.service.log .LogEntry)
*/
public void logged(LogEntry logEntry) {
logger.debug("Log4J: "+ logEntry.getBundle().getSymbolicName() + " " +
logEntry.getMessage());
System.err.println("Sysout: " + logEntry.getBundle().getSymbolicName()
+ " " + logEntry.getMessage());
}
}
My log4.properties is also very simple for this example:
# Set root logger level to DEBUG and its only appender to A1.
log4j.rootLogger=DEBUG, A1
# A1 is set to be a ConsoleAppender.
log4j.appender.A1=org.apache.log4j.ConsoleAppender
# A1 uses PatternLayout.
log4j.appender.A1.layout=org.apache.log4j.PatternLayout
log4j.appender.A1.layout.ConversionPattern=%-4r [%t] %-5p %c %x - %m%n
So If all went well I should have two output lines in the consolebut all
I got is this just after the equinox starts:
osgi> log4j:WARN No appenders could be found for logger
(logger.file.HUMSFileLogListener).
log4j:WARN Please initialize the log4j system properly.
C-HUMS: FileLogger Added C-HUMS LogListener
C-HUMS: FileLogger Sarting C-HUMS Log
I'm thinking the problem migth by with the location of the
log4j.properties file... I'm placing it in the root of my project so it
can be at the root of my jar.
As anyone done this successfully?
Thanks in advance,
Pedro Silva
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.05864 seconds