If your Nucleus component cannot extend GenericService
(for example, because it already extends some other class), you can use the LoggingPropertied
interface.
The LoggingPropertied
interface consists of a single method:
public ApplicationLoggingSender getLogging();
This method returns the application logging instance your component uses for its logging. Using this interface means that you don’t have to implement the entire ApplicationLogging
interface on your subclass, or use another component’s ApplicationLogging
instance, which would mean that your own component’s name would not appear in the log files.
A LoggingPropertied
component would typically implement LoggingPropertied
and ServiceListener
(to get startService
calls so that the component name can be set on the logging instance), and include the following code:
ApplicationLoggingImpl mLogging = new ApplicationLoggingImpl( this.getClass().getName()); public ApplicationLoggingSender getLogging() { return mLogging; } public void startService (ServiceEvent pEvent) throws ServiceException { mLogging.initializeFromServiceEvent(pEvent); } public void stopService() { }
Then, when your component needs to log, it can use code such as the following:
if (getLogging().isLoggingDebug()) {
getLogging().logDebug("Debugging!");
}
Nucleus is now aware of the LoggingPropertied
interface, and will display properties for the ApplicationLogging
instance. The administrative UI also allows you to access the ApplicationLogging
properties, including changing them at runtime.
Nucleus understands simple dot notation for nested property names, with some limitations. So the Nucleus properties file for your component implementing ApplicationLogging
could contain the following to turn on logging debug when your application starts up:
logging.loggingDebug=true
Note that the logging property object must exist before the startService
, since all property settings are applied before startService
is invoked.