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: writes hostname when using customized syslog socket because “unixgram” or “unix” are not recognized as local transports #41960

Closed
larryleguo opened this issue Oct 14, 2020 · 2 comments
Labels
FrozenDueToAge help wanted NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Milestone

Comments

@larryleguo
Copy link

What version of Go are you using (go version)?

$ go version
go version go1.15 linux/amd64

Does this issue reproduce with the latest release?

Yes.

What operating system and processor architecture are you using (go env)?

go env Output
$ go env
GO111MODULE=""
GOARCH="amd64"
GOBIN=""
GOCACHE="/usr/local/google/home/leguo/.cache/go-build"
GOENV="/usr/local/google/home/leguo/.config/go/env"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOINSECURE=""
GOMODCACHE="/usr/local/google/home/leguo/go/pkg/mod"
GONOPROXY=""
GONOSUMDB=""
GOOS="linux"
GOPATH="/usr/local/google/home/leguo/go"
GOPRIVATE=""
GOPROXY="https://proxy.golang.org,direct"
GOROOT="/usr/lib/google-golang"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/usr/lib/google-golang/pkg/tool/linux_amd64"
GCCGO="gccgo"
AR="ar"
CC="clang"
CXX="clang++"
CGO_ENABLED="1"
GOMOD=""
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build869140076=/tmp/go-build -gno-record-gcc-switches"

What did you do?

syslog.New() uses default syslog socket "/dev/log". To specify socket path, syslog.Dial("unixgram", "/dev/log", ...) can be used. The behaviors should be the same but but they are not. Running the attached example code:

syslog_debug.go.txt

$ go run syslog_debug.go; tail /var/log/debug -n 100 | grep 'Syslog debug: logging with'

What did you expect to see?

Oct 9 17:13:33 foo.bar.com default[1804115]: Syslog debug: logging with default socket.
Oct 9 17:13:33 foo.bar.com customized[1804115]: Syslog debug: logging with customized socket.

What did you see instead?

Oct 9 17:13:33 foo.bar.com default[1804115]: Syslog debug: logging with default socket.
Oct 9 17:13:33 foo.bar.com foo.bar.com customized[1804115]: Syslog debug: logging with customized socket.

Host name appears twice in the customized socket. As a result, the hostname will be parsed as programname by rsyslogd.

The reason is that "unixgram" is not considered as a local socket in
https://golang.org/src/log/syslog/syslog.go, line 164:
field "local" will not be set if network is unixgram.

In https://golang.org/src/log/syslog/syslog.go, line 284:
If local is not set, the hostname will be output.

We need to run a dedicated syslog server in Linux. /dev/log cannot be used since it is used by other services.

@ianlancetaylor ianlancetaylor changed the title Syslog writes hostname when using customized syslog socket log/syslog: writes hostname when using customized syslog socket Oct 14, 2020
@ianlancetaylor ianlancetaylor added help wanted NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. labels Oct 14, 2020
@ianlancetaylor ianlancetaylor added this to the Backlog milestone Oct 14, 2020
imxyb pushed a commit to imxyb/go that referenced this issue Oct 21, 2020
imxyb added a commit to imxyb/go that referenced this issue Oct 21, 2020
Signed-off-by: imxyb <xyb4638@gmail.com>
@gopherbot
Copy link

Change https://golang.org/cl/264081 mentions this issue: Fix issue #41960

@gopherbot
Copy link

Change https://golang.org/cl/264297 mentions this issue: log/syslog: set local is true when network equal unixgramorunix``

imxyb added a commit to imxyb/go that referenced this issue Oct 23, 2020
imxyb added a commit to imxyb/go that referenced this issue Oct 24, 2020
imxyb added a commit to imxyb/go that referenced this issue Oct 25, 2020
@odeke-em odeke-em changed the title log/syslog: writes hostname when using customized syslog socket log/syslog: writes hostname when using customized syslog socket because u Oct 25, 2020
@odeke-em odeke-em changed the title log/syslog: writes hostname when using customized syslog socket because u log/syslog: writes hostname when using customized syslog socket because “unixgram” or “unix” are not recognized as local transports Oct 25, 2020
@odeke-em odeke-em modified the milestones: Backlog, Go1.16 Oct 25, 2020
@golang golang locked and limited conversation to collaborators Oct 25, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
FrozenDueToAge help wanted NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants