Class Log

java.lang.Object
org.apache.felix.cm.impl.Log

public class Log extends Object
Log implementation either logging to a LogService or to System.err. The logger can be get using the static logger field. The logger is initialized through start(BundleContext) and set(ServiceReference). It gets cleaned up through stop().
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    private static final String
    The name of the bundle context property defining the maximum log level (value is "felix.cm.loglevel").
    private static final int
     
    private static final String
     
    static final Log
    The shared logger instance.
    private int
     
    private org.osgi.util.tracker.ServiceTracker
     
    private org.osgi.framework.ServiceReference<org.osgi.service.cm.ConfigurationAdmin>
     
  • Constructor Summary

    Constructors
    Constructor
    Description
    Log()
     
  • Method Summary

    Modifier and Type
    Method
    Description
    boolean
    isLogEnabled(int level)
    Is the log level enabled?
    void
    log(int level, String format, Object[] args)
    Log a message in the given level.
    void
    log(int level, String message, Throwable t)
    Log the message with the given level and throwable.
    void
    set(org.osgi.framework.ServiceReference<org.osgi.service.cm.ConfigurationAdmin> ref)
    Set the service reference to the configuration admin in order to include this in every log message.
    void
    start(org.osgi.framework.BundleContext bundleContext)
    Start the tracker for the logger and set the log level according to the configuration.
    void
    Stop the log service tracker and clear the service reference
    private static String
    toString(org.osgi.framework.ServiceReference<?> ref)
    Create a string representation of the service reference

    Methods inherited from class java.lang.Object

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

    • logger

      public static final Log logger
      The shared logger instance.
    • CM_LOG_LEVEL

      private static final String CM_LOG_LEVEL
      The name of the bundle context property defining the maximum log level (value is "felix.cm.loglevel"). The log level setting is only used if there is no OSGi LogService available. Otherwise this setting is ignored.

      This value of this property is expected to be an integer number corresponding to the log level values of the OSGi LogService. That is 1 for errors, 2 for warnings, 3 for informational messages and 4 for debug messages. The default value is 2, such that only warnings and errors are logged in the absence of a LogService.

      See Also:
    • LOG_SERVICE_NAME

      private static final String LOG_SERVICE_NAME
      See Also:
    • CM_LOG_LEVEL_DEFAULT

      private static final int CM_LOG_LEVEL_DEFAULT
      See Also:
    • logTracker

      private volatile org.osgi.util.tracker.ServiceTracker logTracker
    • logLevel

      private volatile int logLevel
    • serviceReference

      private volatile org.osgi.framework.ServiceReference<org.osgi.service.cm.ConfigurationAdmin> serviceReference
  • Constructor Details

    • Log

      public Log()
  • Method Details

    • start

      public void start(org.osgi.framework.BundleContext bundleContext)
      Start the tracker for the logger and set the log level according to the configuration.
      Parameters:
      bundleContext - The bundle context
    • set

      public void set(org.osgi.framework.ServiceReference<org.osgi.service.cm.ConfigurationAdmin> ref)
      Set the service reference to the configuration admin in order to include this in every log message.
      Parameters:
      ref - The service reference
    • stop

      public void stop()
      Stop the log service tracker and clear the service reference
    • isLogEnabled

      public boolean isLogEnabled(int level)
      Is the log level enabled?
      Parameters:
      level - The level
      Returns:
      true if enabled
    • log

      public void log(int level, String format, Object[] args)
      Log a message in the given level. If arguments are provided and contain a ServiceReference then the argument is replaced with the result of toString(ServiceReference).
      Parameters:
      level - The log level
      format - The message text
      args - The optional arguments
    • log

      public void log(int level, String message, Throwable t)
      Log the message with the given level and throwable.
      Parameters:
      level - The log level
      message - The message
      t - The exception
    • toString

      private static String toString(org.osgi.framework.ServiceReference<?> ref)
      Create a string representation of the service reference
      Parameters:
      ref - The service reference
      Returns:
      The string representation