Logging Trace

Emit diagnostic trace from your Talon microservices using tracer objects.

Overview

Talon provides a trace logging framework that allows you to create custom tracers in your application code and emit trace messages at various levels. Tracers are bound to loggers that control trace output destinations and levels.

Creating Tracers

The below code snippet shows an example of creating a Tracer object called "application":

@AppHAPolicy(value = AepEngine.HAPolicy.StateReplication)
public class Application {
    private static final Tracer tracer = Tracer.create("application", Level.INFO);

    @EventHandler
    final public void onMessage(Message message, Repository repository) {
        if (tracer.debug) tracer.log("onMessage entered", Level.DEBUG);
    }
}

The tracer is created with a default level of INFO meaning that the trace statement in the message handler which is emitted at DEBUG level will not be executed by default.

Trace Levels

Tracers support the following trace levels (in increasing order of verbosity):

  • SEVERE - Critical errors

  • WARNING - Warning conditions

  • INFO - Informational messages

  • CONFIG - Configuration messages

  • DIAGNOSE - Diagnostic messages

  • VERBOSE - Verbose diagnostic messages

  • DEBUG - Debug messages

Conditional Tracing

For performance, always check the trace level before emitting trace at levels below INFO:

This ensures that expensive string operations or method calls are only executed when the trace level is enabled.

Logging Trace Messages

Once you've created a tracer, use its log() method to emit trace:

Configuring Trace Output

To enable trace output and control where trace is logged, you need to configure:

  1. Trace Levels - Control which trace messages are emitted

  2. Loggers - Named entities that control trace output

  3. Handlers - Destinations for trace output (stdout, files, network, etc.)

For complete information on configuring trace levels, loggers, and handlers, see Trace Logging Configuration.

Quick Configuration Example

To enable debug level for the "application" tracer and bind it to both console and file output:

DDL Configuration:

System Properties:

Next Steps

  1. Create tracers for different components in your application

  2. Add trace statements at appropriate levels throughout your code

  3. Configure trace levels and handlers for development and production environments

  4. Use conditional tracing for performance-sensitive code paths

Last updated