Skip to content

Logging Configuration

paulcleary edited this page Nov 10, 2015 · 3 revisions

Money allows you to emit span data to logs for forwarding into some log aggregator (LogStash / Splunk / Etc). To facilitate logging use cases, money provides MDC support out-of-the-box to help you correlate log entries.

The MDC values money provides are:

  • moneyTrace - the span id (trace-id, parent-id, span-id) that is currently in scope when the log entry is written.
  • spanName - the name of the span that is in scope when the log entry is written.

This can be extremely valuable when scanning your logs across systems. For example, if you want to see all logs for a given trace, you can simply search by trace-id and see all log entries in all systems that participated in that trace. Yes...that is awesome.

Money uses SLF4J for logging, as such you will need an SLF4J compliant logger to get the benefits. We have traditionally used Logback for our logging needs, specifically the AsyncAppender.

The following is an example logback config file:

<?xml version="1.0" encoding="UTF-8"?>
<configuration debug="false">

    <!-- if you haven't configured logback over jmx you haven't lived -->
    <jmxConfigurator/>

    <!--=========
        Appenders
        =========-->

    <!--
    This is the main log, we are having all things, including money traces, go into the same log file.
    If you do not want that, you just create a separate appender

    Note, the pattern uses the Money MDC value "moneyTrace", this will output the current trace context
    with every log statement.  Very very useful when parsing log files and correlating log entries
    -->    
    <appender name="console" class="ch.qos.logback.core.ConsoleAppender">
        <encoder>
            <pattern>%date{ISO8601} %X{moneyTrace} %X{spanName} %msg%n</pattern>
        </encoder>
    </appender>

    <!--
    This is the Money specific log appender.  We can choose to use a different log pattern than
    the "normal" log entries
    -->
    <appender name="async_money_appender" class="ch.qos.logback.classic.AsyncAppender">
        <param name="queueSize" value="10000"/>
        <param name="discardingThreshold" value="0"/>
        <param name="includeCallerData" value="true"/>
        <appender-ref ref="console"/>
    </appender>

    <!--=======
        Loggers
        =======-->
    <root>
        <level value="info"/>
        <appender-ref ref="async_money_appender"/>
    </root>

</configuration>
Clone this wiki locally