Logfmt Log Formatting
Logfmt is a log format that is easy for humans to read and write, and is supported by AppSignal. It was initially used as the format for the Heroku Logdrains, and is now used by many other logging providers.
Most of our platforms and endpoints support the Logfmt message format, which we'll describe in better details below
Format
Logfmt is a key-value format, where each key-value pair is separated by a space. The key and value are separated by an equals sign (=
). The key-value pairs are appended to the message at the end of the log line.
Any key-value pairs that do not follow the Logfmt format are appended to the message of the log line.
Examples
The following examples show how AppSignal parses logs in the Logfmt format:
Message with attributes
This will be parsed to a log line with the message "this is a message"
, and the following attributes: { "foo": "bar", "duration": 10, "value": "with spaces"}
Message with override
This will be parsed to a log line with the message "I am a message"
, and the following attributes: { "foo": "bar", "duration": 10 }
.
The rest of the original message is ignored, in favor of the message
key.
Attributes only
This will be parsed to a log line with the message "foo=bar duration=100"
, and the following attributes: { "foo": "bar", "duration": 10 }
Formatting Rules
- Keys must be alphanumeric.
- Keys cannot contain spaces, but may contain fullstops (
.
), underscores (_
) and hyphens (-
). - Keys may not contain more than 50 characters
- Values must start with an alphanumeric character, and may not be longer than 100 characters
- No more than 25 attributes per log message.
Key value pairs that do not follow these rules are appended to the message of a log.
Key behavior:
- If a key does not have a value, it will be appended to the message field.
- If a key-value pair has a key with the name of
msg
ormessage
the value of this key will be parsed as the log message. - If no message/msg key is available, the entire log line will be considered the message.