Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Equinox » Using Log4j in Equinox
Using Log4j in Equinox [message #96911] Mon, 10 September 2007 14:51 Go to next message
Pedro Silva is currently offline Pedro SilvaFriend
Messages: 25
Registered: July 2009
Junior Member
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
Re: Using Log4j in Equinox [message #96920 is a reply to message #96911] Mon, 10 September 2007 16:00 Go to previous messageGo to next message
Pedro Silva is currently offline Pedro SilvaFriend
Messages: 25
Registered: July 2009
Junior Member
I've managed to put it to work :) The solution was to create a log4j
fragment bundle with the log4j.properties file inside.

Anyway I would like to hear from someone if this approach is the correct
one.

Thanks,
Pedro Silva

Pedro Silva wrote:
> 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
Re: Using Log4j in Equinox [message #97032 is a reply to message #96920] Mon, 10 September 2007 23:39 Go to previous message
Eclipse UserFriend
Originally posted by: alex_blewitt.yahoo.com

Yeah, that's pretty much the approach I suggested using in

http://www.eclipsezone.com/eclipse/forums/t99588.html

Alex.
Previous Topic:Problem with http.jetty and static content...
Next Topic:EclipseStarter.shutdown() freezes
Goto Forum:
  


Current Time: Thu Apr 25 11:05:24 GMT 2024

Powered by FUDForum. Page generated in 0.02947 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top