How to log in LuciadLightspeed applications

LuciadLightspeed allows you to keep using your preferred logging framework. If you’re not using a logging framework yet, you can stick with the default Java logging framework in the java.util.logger package.

By default, LuciadLightspeed uses that framework to log application messages. The How to configure third-party logging frameworks tutorial explains how to change this.

Configuring LuciadLightspeed logging with the standard Java logging framework

You can configure the Java logging framework globally by modifying $JAVA_HOME/lib/logging.properties. However, you may want to consider creating a custom properties file for your application and specify it as a system property:

Program: Specifying a custom logging properties file
java -Djava.util.logging.config.file=mylogging.properties MyApplication

You can configure the logging level and handlers separately for each class or package. If you don’t configure a class or package explicitly, the settings of its parent package are used instead. For example, the following listing shows how to enable logging at the FINEST level for the class com.luciad.format.shp.TLcdSHPModelDecoder and at the INFO level for all the other LuciadLightspeed classes:

Program: Logging properties file
# Debug/trace logging
com.luciad.format.shp.TLcdSHPModelDecoder.level = FINEST
com.luciad.level = INFO
com.luciad.handlers = java.util.logging.ConsoleHandler
java.util.logging.ConsoleHandler.level = FINEST

# Optionally, you can specify a TLcdJULSimpleFormatter for messages.
# The arguments for the format string are:
#   1: Message
#   2: Logger name
#   3: Level
#   4: Date
#   5: Source class name
#   6: Source method name
#   7: Thread ID
#   8: Throwable
java.util.logging.ConsoleHandler.formatter = com.luciad.util.logging.TLcdJULSimpleFormatter
com.luciad.util.logging.TLcdJULSimpleFormatter.format = %3$s: %5$s#%6$s %1$s (%8$s)\n

To configure the presentation of the log messages, you can associate a formatter with the log handler. If you don’t specify anything, the Java ConsoleHandler uses the standard class SimpleFormatter. For a more flexible message display, you can use the LuciadLightspeed formatter class TLcdJULSimpleFormatter, as illustrated in the Logging properties file example.

You can get the display message by passing the format property as the first argument to the String.format(String, Object…​ args) method and the JUL log record properties as the remaining arguments in this order:

  1. LogRecord.getMessage()

  2. LogRecord.getLoggerName()

  3. LogRecord.getLevel()

  4. LogRecord.getMillis() (as a Date object)

  5. LogRecord.getSourceClassName()

  6. LogRecord.getSourceMethodName()

  7. LogRecord.getThreadID()

  8. LogRecord.getThrown()

The configuration in the Logging properties file example results in log messages displayed as <Log level>: <Class>#<Method> <Message> (<Exception>). For more details on configuring and using the logging framework, see http://docs.oracle.com/javase/1.5.0/docs/guide/logging/.