Package org.apache.felix.cm.impl
Class Log
java.lang.Object
org.apache.felix.cm.impl.Log
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
FieldsModifier and TypeFieldDescriptionprivate static final StringThe name of the bundle context property defining the maximum log level (value is "felix.cm.loglevel").private static final intprivate static final Stringstatic final LogThe shared logger instance.private intprivate org.osgi.util.tracker.ServiceTrackerprivate org.osgi.framework.ServiceReference<org.osgi.service.cm.ConfigurationAdmin> -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionbooleanisLogEnabled(int level) Is the log level enabled?voidLog a message in the given level.voidLog the message with the given level and throwable.voidset(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.voidstart(org.osgi.framework.BundleContext bundleContext) Start the tracker for the logger and set the log level according to the configuration.voidstop()Stop the log service tracker and clear the service referenceprivate static StringtoString(org.osgi.framework.ServiceReference<?> ref) Create a string representation of the service reference
-
Field Details
-
logger
The shared logger instance. -
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
- 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:
trueif enabled
-
log
Log a message in the given level. If arguments are provided and contain aServiceReferencethen the argument is replaced with the result oftoString(ServiceReference).- Parameters:
level- The log levelformat- The message textargs- The optional arguments
-
log
Log the message with the given level and throwable.- Parameters:
level- The log levelmessage- The messaget- The exception
-
toString
Create a string representation of the service reference- Parameters:
ref- The service reference- Returns:
- The string representation
-