Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

enable syslog logger to have access to env and labels #21724

Merged
merged 1 commit into from
Apr 10, 2016
Merged

enable syslog logger to have access to env and labels #21724

merged 1 commit into from
Apr 10, 2016

Conversation

flyinprogrammer
Copy link
Contributor

- What I did
I added env and labels as valid log options for the syslog logger.

- How I did it
Well... there's only 1 commit, I reckon you can figure that out.

- How to verify it
You know I probably could write a test like this one: https://github.com/docker/docker/blob/master/daemon/logger/syslog/syslog_test.go#L40-L45

Or...

I could show you this:

Shell:

$ docker run -it --rm --log-driver syslog --log-opt tag="{{ (.ExtraAttributes nil).MESOS_TASK_ID }}" --log-opt env=MESOS_TASK_ID -e MESOS_TASK_ID=logtester.1234 flyinprogrammer/logtester
+ exec app
2016-04-01 15:22:17.075416751 +0000 UTC stderr msg: 1
2016-04-01 15:22:17.075416751 +0000 UTC stdout msg: 1
2016-04-01 15:22:22.075767762 +0000 UTC stderr msg: 2
2016-04-01 15:22:22.075767762 +0000 UTC stdout msg: 2

/var/log/syslog:

Apr  1 15:22:17 ip-10-27-39-73 docker/logtester.1234[45499]: + exec app
Apr  1 15:22:17 ip-10-27-39-73 docker/logtester.1234[45499]: 2016-04-01 15:22:17.075416751 +0000 UTC stderr msg: 1
Apr  1 15:22:17 ip-10-27-39-73 docker/logtester.1234[45499]: 2016-04-01 15:22:17.075416751 +0000 UTC stdout msg: 1
Apr  1 15:22:22 ip-10-27-39-73 docker/logtester.1234[45499]: 2016-04-01 15:22:22.075767762 +0000 UTC stderr msg: 2
Apr  1 15:22:22 ip-10-27-39-73 docker/logtester.1234[45499]: 2016-04-01 15:22:22.075767762 +0000 UTC stdout msg: 2

So this is pretty cool huh because it starts to address issues like this one:
mesosphere/marathon#717

So that's nifty huh 😸.

- A picture of a cute animal (not mandatory but encouraged)

Alan
Steve!

Signed-off-by: Alan Scherger flyinprogrammer@gmail.com

@LK4D4
Copy link
Contributor

LK4D4 commented Apr 1, 2016

why not
LGTM

@thaJeztah
Copy link
Member

@flyinprogrammer could you make sure to update the documentation as well to mention the new options? https://github.com/docker/docker/blob/master/docs/admin/logging/overview.md#syslog-options

@flyinprogrammer
Copy link
Contributor Author

@thaJeztah is this good enough?

@calavera
Copy link
Contributor

calavera commented Apr 8, 2016

LGTM but it needs a rebase

@flyinprogrammer
Copy link
Contributor Author

@calavera done 😄

As an example of what is possible with the syslog logger:

```
$ docker run -it --rm --log-driver syslog --log-opt tag="{{ (.ExtraAttributes nil).MESOS_TASK_ID }}" --log-opt env=MESOS_TASK_ID -e MESOS_TASK_ID=logtester.1234 flyinprogrammer/logtester
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I built the docs for this, and I think we should wrap this, otherwise only a small part of the example is visible;

screen shot 2016-04-08 at 17 20 07

Also, I suggest to change the label name to something that more clearly stands out as being for "illustrational" purposes (e.g. SOME_ENV_VAR), so:

$ docker run -it --rm \
    --log-driver syslog \
    --log-opt tag="{{ (.ExtraAttributes nil).SOME_ENV_VAR }}" \
    --log-opt env=SOME_ENV_VAR \
    -e SOME_ENV_VAR=logtester.1234 \
    flyinprogrammer/logtester

(I like the idea of the log tester image BTW!)

Signed-off-by: Alan Scherger <flyinprogrammer@gmail.com>
@flyinprogrammer
Copy link
Contributor Author

@thaJeztah thanks for the feedback! You should see your suggestions reflected in the latest push.

As for logtester, it's been pretty helpful for testing log flows, and I should have a post coming out soon where I use it to performance test rsyslog.

@thaJeztah
Copy link
Member

@flyinprogrammer yes, it looks simple and useful, nice 👍

@thaJeztah
Copy link
Member

LGTM

@vdemeester
Copy link
Member

LGTM 🐮

@zquiring01
Copy link

@flyinprogrammer Is there any way to append the labels/environment variables outside of the --log-opt tag parameter? I noticed that the syslog logging driver supports the use of --log-opt label but in testing couldn't get the labels to output. Running the following test:

docker run
--label production_status="testing" -e os="windows"
--log-driver syslog --log-opt syslog-address=udp://0.0.0.0:514
--log-opt labels=production_status,os
--log-opt tag="foobar"
alpine echo hello world

returns:

<30>Aug 18 21:19:35 foobar[2542]: hello world

In this case I want the labels/environment variables to get included in the message section, as oppose to the header (the APP-NAME section).

@flyinprogrammer
Copy link
Contributor Author

So this is still working as designed so far as I can tell:

docker run -it --rm \
--log-driver syslog \
--log-opt tag="{{ (.ExtraAttributes nil).production_status }}--{{ (.ExtraAttributes nil).os }}" \
--log-opt env=os \
--log-opt labels=production_status \
--label production_status="testing" \
--env os="windows" \
flyinprogrammer/logtester

generates:

Sep  2 14:16:42 <hostname> testing--windows[1717]: 2017-09-02 21:16:42.610942081 +0000 UTC stderr msg: 1
Sep  2 14:16:42 <hostname> testing--windows[1717]: 2017-09-02 21:16:42.610942081 +0000 UTC stdout msg: 1

You'll note that the magic of getting your variables into the APP-NAME section is done in --log-opt tag.
Which is documented here.

In this case I want the labels/environment variables to get included in the message section, as oppose to the header (the APP-NAME section).

In order to do this you would need to provide your own syslog format as we've done here to provide support for rfc3164, rfc5424, and rfc5424micro.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

7 participants