|
Knopflerfish OSGi 5.0.0 | ||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.knopflerfish.service.log.LogRef
public class LogRef
LogRef is an utility class that simplifies the use of the LogService.
LogRef let you use the log without worrying about getting new service objects when the log service is restarted. It also supplies methods with short names that does logging with all the different LogService severity types.
To use the LogRef you need to import
org.knopflerfish.service.log.LogRef
and instantiate LogRef with
your bundle context as parameter. The bundle context is used for getting the
LogService and adding a service listener.
if
statement that protects each call to the
LogRef
instance below is there to save the effort required for
creating the message string object in cases where the log will throw away the
log entry due to its unimportance. The user must have this if
-test in his code since that is the only way to avoid constructing the string
object. Placing it in the wrapper (LogRef) will not help due to the design of
the Java programming language.
package org.knopflerfish.example.hello; import org.osgi.framework.*; import org.knopflerfish.service.log.LogRef; public class Hello implements BundleActivator { LogRef log; public void start(BundleContext bundleContext) { log = new LogRef(bundleContext); if (log.doInfo()) log.info("Hello started."); } public void stop(BundleContext bundleContext) { if (log.doDebug()) log.debug("Hello stopped."); } }
LogService
,
LogService
Field Summary |
---|
Fields inherited from interface org.osgi.service.log.LogService |
---|
LOG_DEBUG, LOG_ERROR, LOG_INFO, LOG_WARNING |
Constructor Summary | |
---|---|
LogRef(BundleContext bc)
Create new LogRef object for a given bundle. |
|
LogRef(BundleContext bc,
boolean out)
Create new LogRef object for a given bundle. |
Method Summary | |
---|---|
void |
close()
Close this LogRef object. |
void |
debug(java.lang.String msg)
Log a debug level message |
void |
debug(java.lang.String msg,
ServiceReference<?> sr)
Log a debug level message. |
void |
debug(java.lang.String msg,
ServiceReference<?> sr,
java.lang.Throwable e)
Log a debug level message. |
void |
debug(java.lang.String msg,
java.lang.Throwable e)
Log a debug level message. |
boolean |
doDebug()
Returns true if messages with severity debug or higher are saved by the log. |
boolean |
doError()
Returns true if messages with severity error or higher are saved by the log. |
boolean |
doInfo()
Returns true if messages with severity info or higher are saved by the log. |
protected void |
doLog(java.lang.String msg,
int level,
ServiceReference<?> sr,
java.lang.Throwable e)
Sends a message to the log if possible. |
boolean |
doWarn()
Returns true if messages with severity warning or higher are saved by the log. |
void |
error(java.lang.String msg)
Log an error level message. |
void |
error(java.lang.String msg,
ServiceReference<?> sr)
Log an error level message. |
void |
error(java.lang.String msg,
ServiceReference<?> sr,
java.lang.Throwable e)
Log an error level message. |
void |
error(java.lang.String msg,
java.lang.Throwable e)
Log an error level message. |
int |
getLogLevel()
Returns the current log level. |
void |
info(java.lang.String msg)
Log an info level message. |
void |
info(java.lang.String msg,
ServiceReference<?> sr)
Log an info level message. |
void |
info(java.lang.String msg,
ServiceReference<?> sr,
java.lang.Throwable e)
Log an info level message. |
void |
info(java.lang.String msg,
java.lang.Throwable e)
Log an info level message. |
void |
log(int level,
java.lang.String message)
Log a message. |
void |
log(int level,
java.lang.String message,
java.lang.Throwable exception)
Log a message with an exception. |
void |
log(ServiceReference sr,
int level,
java.lang.String message)
Log a message associated with a specific Service. |
void |
log(ServiceReference sr,
int level,
java.lang.String message,
java.lang.Throwable exception)
Log a message with an exception associated with a specific Service. |
void |
serviceChanged(ServiceEvent evt)
Service listener entry point. |
void |
warn(java.lang.String msg)
Log a warning level message. |
void |
warn(java.lang.String msg,
ServiceReference<?> sr)
Log a warning level message. |
void |
warn(java.lang.String msg,
ServiceReference<?> sr,
java.lang.Throwable e)
Log a warning level message. |
void |
warn(java.lang.String msg,
java.lang.Throwable e)
Log a warning level message. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public LogRef(BundleContext bc, boolean out)
bc
- the bundle context of the bundle that this log ref instance
belongs too.out
- If true print messages on System.out
when there is no
log service.public LogRef(BundleContext bc)
If the system property org.knopflerfish.log.out equals "true", system.out will be used as fallback if no log service is found.
bc
- the bundle context of the bundle that this log ref instance
belongs too.Method Detail |
---|
public void serviceChanged(ServiceEvent evt)
serviceChanged
in interface ServiceListener
evt
- Service eventpublic void close()
protected void doLog(java.lang.String msg, int level, ServiceReference<?> sr, java.lang.Throwable e)
msg
- Human readable string describing the condition.level
- The severity of the message (Should be one of the four predefined
severities).sr
- The ServiceReference
of the service that this message
is associated with.e
- The exception that reflects the condition.public int getLogLevel()
public boolean doDebug()
true
if messages with severity LOG_DEBUG or higher are
included in the log, otherwise false
.public boolean doWarn()
true
if messages with severity LOG_WARNING or higher
are included in the log, otherwise false
.public boolean doInfo()
true
if messages with severity LOG_INFO or higher are
included in the log, otherwise false
.public boolean doError()
true
if messages with severity LOG_ERROR or higher are
included in the log, otherwise false
.public void debug(java.lang.String msg)
msg
- Log message.public void debug(java.lang.String msg, ServiceReference<?> sr)
msg
- Log messagesr
- The ServiceReference
of the service that this message
is associated with.public void debug(java.lang.String msg, java.lang.Throwable e)
msg
- Log messagee
- The exception that reflects the condition.public void debug(java.lang.String msg, ServiceReference<?> sr, java.lang.Throwable e)
msg
- Log messagesr
- The ServiceReference
of the service that this message
is associated with.e
- The exception that reflects the condition.public void info(java.lang.String msg)
msg
- Log messagepublic void info(java.lang.String msg, ServiceReference<?> sr)
msg
- Log messagesr
- The ServiceReference
of the service that this message
is associated with.public void info(java.lang.String msg, java.lang.Throwable e)
msg
- Log messagee
- The exception that reflects the condition.public void info(java.lang.String msg, ServiceReference<?> sr, java.lang.Throwable e)
msg
- Log messagesr
- The ServiceReference
of the service that this message
is associated with.e
- The exception that reflects the condition.public void warn(java.lang.String msg)
msg
- Log messagepublic void warn(java.lang.String msg, ServiceReference<?> sr)
msg
- Log messagesr
- The ServiceReference
of the service that this message
is associated with.public void warn(java.lang.String msg, java.lang.Throwable e)
msg
- Log messagee
- The exception that reflects the condition.public void warn(java.lang.String msg, ServiceReference<?> sr, java.lang.Throwable e)
msg
- Log messagesr
- The ServiceReference
of the service that this message
is associated with.e
- The exception that reflects the condition.public void error(java.lang.String msg)
msg
- Log messagepublic void error(java.lang.String msg, ServiceReference<?> sr)
msg
- Log messagesr
- The ServiceReference
of the service that this message
is associated with.public void error(java.lang.String msg, java.lang.Throwable e)
msg
- Log messagee
- The exception that reflects the condition.public void error(java.lang.String msg, ServiceReference<?> sr, java.lang.Throwable e)
msg
- Log messagesr
- The ServiceReference
of the service that this message
is associated with.e
- The exception that reflects the condition.public void log(int level, java.lang.String message)
log
in interface LogService
level
- The severity of the message. (Should be one of the four predefined
severities.)message
- Human readable string describing the condition.LogService.LOG_ERROR
,
LogService.LOG_WARNING
,
LogService.LOG_INFO
,
LogService.LOG_DEBUG
public void log(int level, java.lang.String message, java.lang.Throwable exception)
log
in interface LogService
level
- The severity of the message. (Should be one of the four predefined
severities.)message
- Human readable string describing the condition.exception
- The exception that reflects the condition.LogService.LOG_ERROR
,
LogService.LOG_WARNING
,
LogService.LOG_INFO
,
LogService.LOG_DEBUG
public void log(ServiceReference sr, int level, java.lang.String message)
log
in interface LogService
sr
- The ServiceReference
of the service that this message
is associated with.level
- The severity of the message. (Should be one of the four predefined
severities.)message
- Human readable string describing the condition.LogService.LOG_ERROR
,
LogService.LOG_WARNING
,
LogService.LOG_INFO
,
LogService.LOG_DEBUG
public void log(ServiceReference sr, int level, java.lang.String message, java.lang.Throwable exception)
log
in interface LogService
sr
- The ServiceReference
of the service that this message
is associated with.level
- The severity of the message. (Should be one of the four predefined
severities.)message
- Human readable string describing the condition.exception
- The exception that reflects the condition.LogService.LOG_ERROR
,
LogService.LOG_WARNING
,
LogService.LOG_INFO
,
LogService.LOG_DEBUG
|
Knopflerfish OSGi 5.0.0 | ||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |