1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89
|
---
title: "Logging configuration"
layout: default
---
# Logging configuration
## Structured logging
PuppetDB uses logback, a standard Java logging library. In certain subsystems,
namely HA, we provide extended structured logging information. By configuring
logback appropriately, you get JSON-formatted log messages with event-specific
fields in each message.
## Common fields
If you use the recommended logger configuration, as described below, you will
see the following fields in each JSON log message:
* @timestamp
* message
* logger_name
* thread_name
* level
* level_value (numeric, suitable for sorting)
* stack_trace
Additional relevant fields may be added in any given message, but this base set
will always be present.
## JSON text
If you want to log JSON data where you would otherwise log regular text, replace the 'encoder' element in
your logback.xml with this one:
<encoder class="net.logstash.logback.encoder.LoggingEventCompositeJsonEncoder">
<providers>
<timestamp/>
<message/>
<loggerName/>
<threadName/>
<logLevel/>
<logLevelValue/>
<stackTrace/>
<logstashMarkers/>
</providers>
</encoder>
Even though this says 'logstash' on it, it works completely independently from
any log aggregation system. The final `<logstashMarkers/>` element inserts our
custom properties into each JSON message.
## Logback integration
You can also log directly to logstash with an appender configured like this:
<appender name="stash" class="net.logstash.logback.appender.LogstashTcpSocketAppender">
<remoteHost>logging.dev</remoteHost>
<port>4560</port>
<encoder class="net.logstash.logback.encoder.LoggingEventCompositeJsonEncoder">
<providers>
<timestamp/>
<message/>
<loggerName/>
<threadName/>
<logLevel/>
<logLevelValue/>
<stackTrace/>
<logstashMarkers/>
</providers>
</encoder>
</appender>
You will also need to add a reference to the appender from the `<root>` element:
<root>
...
<appender-ref ref="stash" />
</root>
## References
These example configurations should get you started. For more advanced
scenarios, the respective tools have good documentation.
* Logstash Appender: https://github.com/logstash/logstash-logback-encoder#tcp
* JSON Encoder: https://github.com/logstash/logstash-logback-encoder#composite_encoder
* Logback configuration: http://logback.qos.ch/manual/configuration.html
|