Created
January 29, 2018 18:50
-
-
Save marcbachmann/00aca56839d9ba886fce1faf10faa355 to your computer and use it in GitHub Desktop.
docker container logs using rsyslog & journald
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ "log-driver": "journald", "log-opts": {"tag": "{{.Name}}/{{.ID}}"}} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module(load="mmjsonparse") | |
template( | |
name="json_docker" | |
type="list" | |
option.casesensitive="on" | |
) { | |
constant(value="{") | |
constant(value="\"@timestamp\":\"") property(name="timereported" dateFormat="rfc3339" date.inUTC="on") | |
constant(value="\",\"hostname\":\"") property(name="hostname") | |
constant(value="\",\"container_id\":\"") property(name="$!CONTAINER_ID") | |
constant(value="\",\"container_name\":\"") property(name="$!CONTAINER_NAME") | |
constant(value="\",\"container_tag\":\"") property(name="$!CONTAINER_TAG") | |
constant(value="\",") property(name="$!json" position.from="2") | |
constant(value="\n") | |
} | |
template( | |
name="string_docker" | |
type="list" | |
option.casesensitive="on" | |
) { | |
constant(value="{") | |
constant(value="\"@timestamp\":\"") property(name="timereported" dateFormat="rfc3339" date.inUTC="on") | |
constant(value="\",\"hostname\":\"") property(name="hostname") | |
constant(value="\",\"container_id\":\"") property(name="$!CONTAINER_ID") | |
constant(value="\",\"container_name\":\"") property(name="$!CONTAINER_NAME") | |
constant(value="\",\"container_tag\":\"") property(name="$!CONTAINER_TAG") | |
constant(value="\",\"msg\":\"") property(name="rawmsg") | |
constant(value="\"}\n") | |
} | |
template( | |
name="docker_container_file" | |
type="string" | |
string="/var/log/docker/%$!CONTAINER_TAG%.log" | |
option.casesensitive="on" | |
) | |
if ($!CONTAINER_NAME != "") then { | |
action(type="mmjsonparse" cookie="" container="!json") | |
if ($parsesuccess == "OK") then { | |
unset $!json!@timestamp; | |
unset $!json!hostname; | |
unset $!json!container_id; | |
unset $!json!container_name; | |
unset $!json!container_tag; | |
action(name="docker-containers-combined" type="omfile" file="/var/log/docker_combined.log" template="json_docker") | |
action(name="docker-containers" type="omfile" dynaFile="docker_container_file" template="json_docker") | |
} else { | |
action(name="docker-containers-combined" type="omfile" file="/var/log/docker_combined.log" template="string_docker") | |
action(name="docker-containers" type="omfile" dynaFile="docker_container_file" template="string_docker") | |
} | |
stop | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I needed the following module loading to automatically load from journald
module(load="imjournal" StateFile="imjournal.state")