public class Logger extends Object implements 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.
Modifier and Type | Field and Description |
---|---|
static int |
LOG_DEBUG |
static int |
LOG_ERROR |
static int |
LOG_INFO |
static int |
LOG_WARNING |
Constructor and Description |
---|
Logger() |
Modifier and Type | Method and Description |
---|---|
protected void |
doLog(Bundle bundle,
ServiceReference sr,
int level,
String msg,
Throwable throwable) |
int |
getLogLevel() |
void |
log(Bundle bundle,
int level,
String msg) |
void |
log(Bundle bundle,
int level,
String msg,
Throwable throwable) |
void |
log(int level,
String msg) |
void |
log(int level,
String msg,
Throwable throwable) |
void |
log(ServiceReference sr,
int level,
String msg) |
void |
log(ServiceReference sr,
int level,
String msg,
Throwable throwable) |
void |
serviceChanged(ServiceEvent event)
This method implements the callback for the ServiceListener interface.
|
void |
setLogLevel(int i) |
protected void |
setSystemBundleContext(BundleContext context) |
public static final int LOG_ERROR
public static final int LOG_WARNING
public static final int LOG_INFO
public static final int LOG_DEBUG
public final void setLogLevel(int i)
public final int getLogLevel()
protected void setSystemBundleContext(BundleContext context)
public final void log(int level, String msg)
public final void log(ServiceReference sr, int level, String msg)
public final void log(ServiceReference sr, int level, String msg, Throwable throwable)
protected void doLog(Bundle bundle, ServiceReference sr, int level, String msg, Throwable throwable)
public final void serviceChanged(ServiceEvent event)
serviceChanged
in interface ServiceListener
event
- The ServiceEvent
object.Copyright © 2007–2018 The Apache Software Foundation. All rights reserved.