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 do not have to implement the entire ApplicationLogging interface on your subclass, or use another component’s ApplicationLogging instance, which means that your own component’s name does not appear in the log files.

A LoggingPropertied component typically implements LoggingPropertied and ServiceListener (to get startService calls so that the component name can be set on the logging instance), and includes 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 displays properties for the ApplicationLogging instance. The administrative UI also lets you 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 can contain the following to turn on logging debug when your application starts up:

logging.loggingDebug=true

Note: The logging property object must exist before the startService, because all property settings are applied before startService is invoked.


Copyright © 1997, 2015 Oracle and/or its affiliates. All rights reserved. Legal Notices