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

log/syslog: formatting issue #5803

Closed
gopherbot opened this issue Jun 27, 2013 · 15 comments
Closed

log/syslog: formatting issue #5803

gopherbot opened this issue Jun 27, 2013 · 15 comments
Milestone

Comments

@gopherbot
Copy link

by jonas@pfenniger.name:

It seems that the go syslog package emits syslogs in a different way than other programs
creating variations in the output format.
The problem is that there is some duplication in the output that's not necessary.

Here are outputs on different machines. The first lines comes from my go socketmaster
project ( https://github.com/pandastream/socketmaster ) and the second line is just
something else for comparison:

On Ubuntu Precise amd64 (ryslog 5.8.6-1ubuntu8.4 with default config):

    2013-06-27T22:03:18.480508+00:00 i-5954eb33 2013-06-27T22:03:18Z i-5954eb33 socketmaster[15089]: Listening on tcp://:8080
    2013-06-27T22:26:22.306421+00:00 i-5954eb33 nginx: - 10.198.69.201 - - [27/Jun/2013:22:26:22 +0000] "-" 400 0 "-" "-" "-"

On OSX 10.8.4:

    27/06/2013 22:57:58.000 2013-06-27T22[-1]: 57:58+01:00 Big-Whoop.local socketmaster[4807]: Listening on tcp://:8080
    27/06/2013 22:46:25.576 GitX[82631]: Loaded 5287 commits in 0.100447 seconds (52634.723275/sec)

Go 1.0 and 1.1 produce the same output.

After looking around a bit in the code it seems that:
 * Go uses /dev/log or /var/run/syslog instead of the syscall that the other programs use
 * Go writes a full network-formatted syslog line even for localhost
 * It seems that the system logger then prepends it's own info which explains the duplication

So I guess my question is, would it be possible to change the go runtime to use the
syscall like everyone ?

Cheers,
  Jonas
@robpike
Copy link
Contributor

robpike commented Jun 27, 2013

Comment 1:

If I had my druthers, I'd delete the log/syslog package. Lucky for you, the Go 1
compatibility promise stays my hand.
Where is the guarantee that the output is system-independent?

Labels changed: added priority-later, removed priority-triage.

Status changed to Accepted.

@ianlancetaylor
Copy link
Contributor

Comment 2:

Note that there is no syslog syscall.  There is a library routine.  We could change the
log/syslog package to use that library routine by turning it into a cgo package, like
os/user.

@gopherbot
Copy link
Author

Comment 3 by jonas@pfenniger.name:

Heh, the log/syslog package is good given the year of inherited legacy in the format.
I had a look and it seems that only linux provides a syscall ( SYS_SYSLOG = 103 ) ? But
I don't really understand "library routine", I'll have to take a look at os/user more
closely.
Another different of the socket connection I just found out is that the program will
fail to open the socket  if the syslog server is down (obviously). Other programs keep
logging in the void happily.

@gopherbot
Copy link
Author

Comment 4 by jgc@cloudflare.com:

Is the main issue here that syslog.go inserts the hostname when on a unix socket? This
actually fails with the standard syslog-ng configuration post 3.2.

@gopherbot
Copy link
Author

Comment 5 by jonas@pfenniger.name:

By looking at the glibc[1] it seems that the local format doesn't have the hostname and
the time sprintf format is "%h %e %T". The equivalent in Go is time.Stamp instead of
time.RFC3339 that we're currently using. I also don't see the "\n" ending logic but see
a \0 added if the stream is a SOCK_STREAM.
[1]:
http://repo.or.cz/w/glibc.git/blob/6d52618b15cbe25ed4822ac51321db292f28ccda:/misc/syslog.c

@gopherbot
Copy link
Author

Comment 6 by jonas@pfenniger.name:

Here is the output I get on Linux with `strace -s 1024 ./a.out` after compiling the
attached foo.c program:
   sendto(3, "<141>Jul  9 11:26:41 exampleprog[21978]: TESTING", 48, MSG_NOSIGNAL, NULL, 0) = 48
I tried running dtruss on OSX to see if the format was the same but I don't see a write
or sendto in the output...

Attachments:

  1. foo.c (212 bytes)

@gopherbot
Copy link
Author

Comment 7 by jonas@pfenniger.name:

The hg tools drive me nuts.
Attached you'll find a patch that changes the syslog formatting when sending locally. I
tested it on Ubuntu and OSX.

Attachments:

  1. fixes-local-syslog-formatting.patch (1146 bytes)

@robpike
Copy link
Contributor

robpike commented Jul 26, 2013

Comment 8:

We can't accept patches this way. Please follow the contribution instructions, with our
apologies and gratitude.

@gopherbot
Copy link
Author

Comment 9 by jonas@pandastream.com:

I don't know if it's intentional but the contribution difficulty is relatively high. Not
only am I not familiar with Mercurial but I also don't know what applies (eg: from
tutorials) since the codereview system seem to be changing some of it's semantic. Now
I'm getting a cryptic error and I get I'll have to do some python spelunking to find the
root cause.
$ hg change
Issue created. URL: https://golang.org/cl/11988043
Sun Jul 28 15:29:45 2013 uploading change to description
abort: HTTP Error 403: Forbidden

@rsc
Copy link
Contributor

rsc commented Jul 30, 2013

Comment 10:

Labels changed: added go1.2maybe.

@gopherbot
Copy link
Author

Comment 11 by jonas@pandastream.com:

Ok I finally got around to make the codereview working. upload.py is a much easier
method than the mercurial plugin.
This is a solution for the current release: https://golang.org/cl/12680048
This is a solution against 17413:2fe813f4f3c2 : https://golang.org/cl/12671045

@bradfitz
Copy link
Contributor

bradfitz commented Aug 9, 2013

Comment 12:

Run "hg mail 12680048"

@bradfitz
Copy link
Contributor

bradfitz commented Aug 9, 2013

Comment 13:

Also, the issue description's first line should start with "log/syslog: "

@gopherbot
Copy link
Author

Comment 14 by zimba.tm:

Sorry I'm having some issues with the codereview tool, seems like google apps account
aren't working properly. In any case here is another revision of the patch:
https://golang.org/cl/12717044/

@rsc
Copy link
Contributor

rsc commented Sep 9, 2013

Comment 15:

This issue was closed by revision 87a6d75.

Status changed to Fixed.

@rsc rsc added this to the Go1.2 milestone Apr 14, 2015
@rsc rsc removed the go1.2maybe label Apr 14, 2015
@golang golang locked and limited conversation to collaborators Jun 24, 2016
This issue was closed.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

5 participants