Class LogWrapper
java.lang.Object
org.apache.felix.eventadmin.impl.util.LogWrapper
public class LogWrapper
extends java.lang.Object
This class mimics the standard OSGi
LogService interface. An
instance of this class will be used by the EventAdmin for all logging. The
implementation of this class sends log messages to standard output, if no
LogService is present; it uses a log service if one is
installed in the framework. To do that without creating a hard dependency on the
package it uses fully qualified class names and registers a listener with the
framework hence, it does not need access to the LogService class but will
use it if the listener is informed about an available service. By using a
DynamicImport-Package dependency we don't need the package but
use it if present. Additionally, all log methods prefix the log message with
EventAdmin: .
There is one difference in behavior from the standard OSGi LogService.
This logger has a m_logLevel property which decides what messages
get logged.- Author:
- Felix Project Team
- See Also:
LogService
-
Field Summary
Fields Modifier and Type Field Description static intLOG_DEBUGDEBUG LEVELstatic intLOG_ERRORERROR LEVELstatic intLOG_INFOINFO LEVELstatic intLOG_WARNINGWARNING LEVEL -
Method Summary
Modifier and Type Method Description static LogWrappergetLogger()Returns the singleton instance of this LogWrapper that can be used to send log messages to all currently available LogServices or to standard output, respectively.intgetLogLevel()voidlog(int level, java.lang.String msg)Log a message with the given log level.voidlog(int level, java.lang.String msg, java.lang.Throwable ex)Log a message with the given log level and the associated exception.voidlog(org.osgi.framework.ServiceReference<?> sr, int level, java.lang.String msg)Log a message with the given log level together with the associated service reference.voidlog(org.osgi.framework.ServiceReference<?> sr, int level, java.lang.String msg, java.lang.Throwable ex)Log a message with the given log level, the associated service reference and exception.static voidsetContext(org.osgi.framework.BundleContext context)Set theBundleContextof the bundle.voidsetLogLevel(int logLevel)Change the current log level.
-
Field Details
-
LOG_ERROR
public static final int LOG_ERRORERROR LEVEL- See Also:
LogService.LOG_ERROR, Constant Field Values
-
LOG_WARNING
public static final int LOG_WARNINGWARNING LEVEL- See Also:
LogService.LOG_WARNING, Constant Field Values
-
LOG_INFO
public static final int LOG_INFOINFO LEVEL- See Also:
LogService.LOG_INFO, Constant Field Values
-
LOG_DEBUG
public static final int LOG_DEBUGDEBUG LEVEL- See Also:
LogService.LOG_DEBUG, Constant Field Values
-
-
Method Details
-
getLogger
Returns the singleton instance of this LogWrapper that can be used to send log messages to all currently available LogServices or to standard output, respectively.- Returns:
- the singleton instance of this LogWrapper.
-
setContext
public static void setContext(org.osgi.framework.BundleContext context)Set theBundleContextof the bundle. This method registers a service listener for LogServices with the framework that are subsequently used to log messages.If the bundle context is
null, the service listener is unregistered and all remaining references to LogServices dropped before internally clearing the bundle context field.- Parameters:
context- The context of the bundle.
-
log
public void log(int level, java.lang.String msg)Log a message with the given log level. Note that this will prefix the message withEventAdmin:.- Parameters:
level- The log level with which to log the msg.msg- The message to log.
-
log
public void log(int level, java.lang.String msg, java.lang.Throwable ex)Log a message with the given log level and the associated exception. Note that this will prefix the message withEventAdmin:.- Parameters:
level- The log level with which to log the msg.msg- The message to log.ex- The exception associated with the message.
-
log
public void log(org.osgi.framework.ServiceReference<?> sr, int level, java.lang.String msg)Log a message with the given log level together with the associated service reference. Note that this will prefix the message withEventAdmin:.- Parameters:
sr- The reference of the service associated with this message.level- The log level with which to log the msg.msg- The message to log.
-
log
public void log(org.osgi.framework.ServiceReference<?> sr, int level, java.lang.String msg, java.lang.Throwable ex)Log a message with the given log level, the associated service reference and exception. Note that this will prefix the message withEventAdmin:.- Parameters:
sr- The reference of the service associated with this message.level- The log level with which to log the msg.msg- The message to log.ex- The exception associated with the message.
-
setLogLevel
public void setLogLevel(int logLevel)Change the current log level. Log level decides what messages gets logged. Any message with a log level higher than the currently set log level is not logged.- Parameters:
logLevel- new log level
-
getLogLevel
public int getLogLevel()- Returns:
- current log level.
-