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 int LOG_DEBUG
    DEBUG LEVEL
    static int LOG_ERROR
    ERROR LEVEL
    static int LOG_INFO
    INFO LEVEL
    static int LOG_WARNING
    WARNING LEVEL
  • Method Summary

    Modifier and Type Method Description
    static LogWrapper 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.
    int getLogLevel()  
    void log​(int level, java.lang.String msg)
    Log a message with the given log level.
    void log​(int level, java.lang.String msg, java.lang.Throwable ex)
    Log a message with the given log level and the associated exception.
    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.
    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.
    static void setContext​(org.osgi.framework.BundleContext context)
    Set the BundleContext of the bundle.
    void setLogLevel​(int logLevel)
    Change the current log level.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

  • Method Details

    • getLogger

      public static LogWrapper 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 the BundleContext of 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 with EventAdmin: .
      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 with EventAdmin: .
      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 with EventAdmin: .
      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 with EventAdmin: .
      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.