Skip to content

Add syslog logging driver - #11458

Merged
LK4D4 merged 1 commit into
moby:masterfrom
ibuildthecloud:syslog
Mar 23, 2015
Merged

LK4D4 merged 1 commit into
moby:masterfrom
ibuildthecloud:syslog

Conversation

@ibuildthecloud

Copy link
Copy Markdown
Contributor

This PR adds support for logging to syslog from Docker by using the go built in syslog package. This code uses the existing logging driver framework added to Docker 1.6. An example output to syslog looks like

Mar 18 00:36:04 inotmac docker[28485]: 94ce4ded774b:                 _._                                                  
Mar 18 00:36:04 inotmac docker[28485]: 94ce4ded774b:            _.-``__ ''-._                                             
Mar 18 00:36:04 inotmac docker[28485]: 94ce4ded774b:       _.-``    `.  `_.  ''-._           Redis 2.8.19 (00000000/0) 64 bit
Mar 18 00:36:04 inotmac docker[28485]: 94ce4ded774b:   .-`` .-```.  ```\/    _.,_ ''-._                                   
Mar 18 00:36:04 inotmac docker[28485]: 94ce4ded774b:  (    '      ,       .-`  | `,    )     Running in stand alone mode
Mar 18 00:36:04 inotmac docker[28485]: 94ce4ded774b:  |`-._`-...-` __...-.``-._|'` _.-'|     Port: 6379
Mar 18 00:36:04 inotmac docker[28485]: 94ce4ded774b:  |    `-._   `._    /     _.-'    |     PID: 1
Mar 18 00:36:04 inotmac docker[28485]: 94ce4ded774b:   `-._    `-._  `-./  _.-'    _.-'                                   
Mar 18 00:36:04 inotmac docker[28485]: 94ce4ded774b:  |`-._`-._    `-.__.-'    _.-'_.-'|                                  
Mar 18 00:36:04 inotmac docker[28485]: 94ce4ded774b:  |    `-._`-._        _.-'_.-'    |           http://redis.io        
Mar 18 00:36:04 inotmac docker[28485]: 94ce4ded774b:   `-._    `-._`-.__.-'_.-'    _.-'                                   
Mar 18 00:36:04 inotmac docker[28485]: 94ce4ded774b:  |`-._`-._    `-.__.-'    _.-'_.-'|                                  
Mar 18 00:36:04 inotmac docker[28485]: 94ce4ded774b:  |    `-._`-._        _.-'_.-'    |                                  
Mar 18 00:36:04 inotmac docker[28485]: 94ce4ded774b:   `-._    `-._`-.__.-'_.-'    _.-'                                   
Mar 18 00:36:04 inotmac docker[28485]: 94ce4ded774b:       `-._    `-.__.-'    _.-'                                       
Mar 18 00:36:04 inotmac docker[28485]: 94ce4ded774b:           `-._        _.-'                                           
Mar 18 00:36:04 inotmac docker[28485]: 94ce4ded774b:               `-.__.-'                                               
Mar 18 00:36:04 inotmac docker[28485]: 94ce4ded774b: 
Mar 18 00:36:04 inotmac docker[28485]: 94ce4ded774b: [1] 18 Mar 07:36:04.448 # Server started, Redis version 2.8.19

NOTE: Credit goes to @wlan0 for the development of this, I'm just submitting the PR

@GordonTheTurtle

Copy link
Copy Markdown
Contributor

Can you please sign your commits following these rules:

https://github.com/docker/docker/blob/master/CONTRIBUTING.md#sign-your-work

The easiest way to do this is to amend the last commit:

$ git clone -b "syslog" [email protected]:ibuildthecloud/docker.git somewhere
$ cd somewhere
$ git commit --amend -s --no-edit
$ git push -f

This will update the existing PR, so you do not need to open a new one.

Comment thread docs/sources/reference/run.md Outdated

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

It shouldn't be impossible to get docker logs to work with syslog, although I'm ok with it not making it in right away

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

@sirupsen Yup, I think it's totally possible.
@ibuildthecloud We write not JSON to syslog if I'm understanding code right.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Was just about to say something similar. This document says it writes JSON, but the example output in the PR description isn't JSON.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

@LK4D4 thats right. I initially started off with a JSON logger and then changed it. I'll fix the docs

@sirupsen

Copy link
Copy Markdown
Contributor

There's a bunch of other docs where you need to add it, especially as a CLI example. The initial PR points out those places. Also needs some tests. Other than that, this looks good.

Comment thread daemon/container.go

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Why only 12 bytes?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

The container id is too long and takes up a large portion of the log line.

@phemmer

phemmer commented Mar 18, 2015

Copy link
Copy Markdown
Contributor

One caveat with writing to syslog is that /dev/log (which syslog uses) can be a SOCK_STREAM (as opposed to SOCK_DGRAM) which blocks if the buffer fills up on the other end, such as if syslog stops reading (rsyslog is notorious for this). Once it blocks, and the buffer between the application inside the container and docker fills up, the application inside the container will block trying to write to STDOUT/STDERR.

If we want to handle this, the only solution to this is to drop log entries if writing to syslog blocks. I can't think of any way of doing this other than introducing a channel and starting up a goroutine which reads off the channel and calls writer.Err/writer.Info

@LK4D4

LK4D4 commented Mar 18, 2015

Copy link
Copy Markdown
Contributor

@phemmer also there is bug in golang syslog package golang/go#5932 :( I solved it with copying std syslog and adding WriteDeadline for connection.

@ibuildthecloud

Copy link
Copy Markdown
Contributor Author

@LK4D4 @phemmer Do you think we need to address this syslog blocking issue in this PR?

@LK4D4

LK4D4 commented Mar 18, 2015

Copy link
Copy Markdown
Contributor

@ibuildthecloud I don't know actually how to do this, because Write is not low-level enough to interrupt it.
@phemmer Actually application won't be blocked. We use pre-read tactics for stdout/stderr pipes. So probably fine for now.

@phemmer

phemmer commented Mar 18, 2015

Copy link
Copy Markdown
Contributor

Actually application won't be blocked. We use pre-read tactics for stdout/stderr pipes. So probably fine for now.

I don't follow. There's a buffer somewhere, that buffer is going to get full, and something is going to block (unless we're already discarding data when buffers fill up).

@LK4D4

LK4D4 commented Mar 18, 2015

Copy link
Copy Markdown
Contributor

@phemmer Buffer just will grow uncontrollable inside docker :) and after #10347 it'll became more smart.

@wlan0

wlan0 commented Mar 18, 2015

Copy link
Copy Markdown
Contributor

@LK4D4 I updated the code based on the comments and added documentation following the logging drivers PR.

Comment thread daemon/config.go Outdated

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This entry is unfortunately too long and is causing a test to fail.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Haha :) Probably we should remove listing of all possible drivers.

@ibuildthecloud
ibuildthecloud force-pushed the syslog branch 2 times, most recently from ec0174e to fe04889 Compare March 19, 2015 19:30
@crosbymichael

Copy link
Copy Markdown
Contributor

Nice, moving to code review

Comment thread daemon/logger/syslog/syslog.go Outdated

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I should vote for Sprintf here as it is more readable

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I agree. Will change it

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Should this be lower case?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

The name of json-file driver is 'JSONFile', I saw that and used 'Syslog' here.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

ok

@jessfraz jessfraz added dco/yes and removed dco/no labels Mar 20, 2015
Signed-off-by: wlan0 <[email protected]>
@ibuildthecloud

Copy link
Copy Markdown
Contributor Author

I pulled in the latest commit from @wlan0, I think all changes have been addressed at this time.

Comment thread daemon/config.go

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Nitpick: containers => container's

@jessfraz

Copy link
Copy Markdown
Contributor

cool it works! I do really like how simple the implementaion is too

@jessfraz

Copy link
Copy Markdown
Contributor

LGTM

@LK4D4

LK4D4 commented Mar 23, 2015

Copy link
Copy Markdown
Contributor

LGTM

LK4D4 added a commit that referenced this pull request Mar 23, 2015
@LK4D4
LK4D4 merged commit 65e21f5 into moby:master Mar 23, 2015
@neurogenesis

Copy link
Copy Markdown

👍 thanks to all for the syslog functionality.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Sorry, but this mutex seems not to be anywhere

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Yup, it's task for docker birthday :)
#11659

@jberryman

Copy link
Copy Markdown

We'd like to be able to specify the socket to use instead of /dev/log, so that we can run a simple socket server to process logs. Is that easily done? Should I open another issue?

@LK4D4

LK4D4 commented Apr 20, 2015

Copy link
Copy Markdown
Contributor

@jberryman Yup, is is easy to add it when --log-opts PR will be merged.

@jberryman

Copy link
Copy Markdown

@LK4D4 Oh that would be great. I think this is the PR you're referring to: #12422

@grayhemp

grayhemp commented Jun 3, 2015

Copy link
Copy Markdown

Some new ideas around it #13726. Could you guys please take a look?

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.