## org.apache.felix.httplite.osgi
Class Logger

    java.lang.Object
      org.apache.felix.httplite.osgi.Logger

All Implemented Interfaces:
  java.util.EventListener, org.osgi.framework.ServiceListener

    public class Logger

extends java.lang.Object
implements org.osgi.framework.ServiceListener

This class mimics the standard OSGi `LogService` interface. An instance of this class is used by the framework for all logging. By default this class logs messages to standard out. The log level can be set to control the amount of logging performed, where a higher number results in more logging. A log level of zero turns off logging completely.

The log levels match those specified in the OSGi Log Service (i.e., 1 = error, 2 = warning, 3 = information, and 4 = debug). The default value is 1.

This class also uses the System Bundle's context to track log services and will use the highest ranking log service, if present, as a back end instead of printing to standard out. The class uses reflection to invoking the log service's method to avoid a dependency on the log interface.

Field Summary
`static int` `LOG_DEBUG` DEBUG level
`static int` `LOG_ERROR` ERROR level
`static int` `LOG_INFO` INFO level
`static int` `LOG_WARNING` WARNING level

Constructor Summary
`Logger()`

Method Summary
`protected void` `doLog(org.osgi.framework.Bundle bundle, org.osgi.framework.ServiceReference sr, int level, java.lang.String msg, java.lang.Throwable throwable)`
`int` `getLogLevel()`
`void` `log(org.osgi.framework.Bundle bundle, int level, java.lang.String msg)`
`void` `log(org.osgi.framework.Bundle bundle, int level, java.lang.String msg, java.lang.Throwable throwable)`
`void` `log(int level, java.lang.String msg)`
`void` `log(int level, java.lang.String msg, java.lang.Throwable throwable)`
`void` `log(org.osgi.framework.ServiceReference sr, int level, java.lang.String msg)`
`void` `log(org.osgi.framework.ServiceReference sr, int level, java.lang.String msg, java.lang.Throwable throwable)`
`void` `serviceChanged(org.osgi.framework.ServiceEvent event)` This method implements the callback for the ServiceListener interface.
`void` `setLogLevel(int i)`
`protected void` `setSystemBundleContext(org.osgi.framework.BundleContext context)`

Methods inherited from class java.lang.Object
`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

Field Detail

### LOG_ERROR

    public static final int LOG_ERROR

  ERROR level

  See Also:
    Constant Field Values

### LOG_WARNING

    public static final int LOG_WARNING

  WARNING level

  See Also:
    Constant Field Values

### LOG_INFO

    public static final int LOG_INFO

  INFO level

  See Also:
    Constant Field Values

### LOG_DEBUG

    public static final int LOG_DEBUG

  DEBUG level

  See Also:
    Constant Field Values

Constructor Detail

### Logger

    public Logger()

Method Detail

### setLogLevel

    public final void setLogLevel(int i)

  Parameters:
    `i` - log level

### getLogLevel

    public final int getLogLevel()

  Returns:
    current log level

### setSystemBundleContext

    protected void setSystemBundleContext(org.osgi.framework.BundleContext context)

### log

    public final void log(int level,
                          java.lang.String msg)

  Parameters:
    `level` - log level
    `msg` - message to log

### log

    public final void log(int level,
                          java.lang.String msg,
                          java.lang.Throwable throwable)

  Parameters:
    `level` - log level
    `msg` - message to log
    `throwable` - error to log

### log

    public final void log(org.osgi.framework.ServiceReference sr,
                          int level,
                          java.lang.String msg)

  Parameters:
    `sr` - service reference to log
    `level` - level to log
    `msg` - message to log

### log

    public final void log(org.osgi.framework.ServiceReference sr,
                          int level,
                          java.lang.String msg,
                          java.lang.Throwable throwable)

  Parameters:
    `sr` - service reference to log
    `level` - level to log
    `msg` - message to log
    `throwable` - error to log

### log

    public final void log(org.osgi.framework.Bundle bundle,
                          int level,
                          java.lang.String msg)

  Parameters:
    `bundle` - bundle to log
    `level` - level to log
    `msg` - message to log

### log

    public final void log(org.osgi.framework.Bundle bundle,
                          int level,
                          java.lang.String msg,
                          java.lang.Throwable throwable)

  Parameters:
    `bundle` - source of log event
    `level` - level to log
    `msg` - message to log
    `throwable` - error to log

### doLog

    protected void doLog(org.osgi.framework.Bundle bundle,
                         org.osgi.framework.ServiceReference sr,
                         int level,
                         java.lang.String msg,
                         java.lang.Throwable throwable)

### serviceChanged

    public final void serviceChanged(org.osgi.framework.ServiceEvent event)

  This method implements the callback for the ServiceListener interface. It is public as a byproduct of implementing the interface and should not be called directly. This method tracks run-time changes to log service availability. If the log service being used by the framework's logging mechanism goes away, then this will try to find an alternative. If a higher ranking log service is registered, then this will switch to the higher ranking log service.

  Specified by:
    `serviceChanged` in interface `org.osgi.framework.ServiceListener`

Copyright © 2006-2012 The Apache Software Foundation. All Rights Reserved.