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: local messages (syslog.New()) do not work on macOS Monterey/Ventura #59229

Open
craig65535 opened this issue Mar 24, 2023 · 2 comments
Labels
help wanted NeedsDecision Feedback is required from experts, contributors, and/or the community before a change can be made. OS-Darwin
Milestone

Comments

@craig65535
Copy link

craig65535 commented Mar 24, 2023

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

$ go version
1.18.10

Does this issue reproduce with the latest release?

Yes

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

darwin/arm64

$ sw_vers
ProductName:            macOS
ProductVersion:         13.2.1
BuildVersion:           22D68

What did you do?

package main

import (
	"log/syslog"
)

func main() {
	msgStr := `hello`
	w, err := syslog.New(syslog.LOG_WARNING|syslog.LOG_DAEMON, ``)
	if err != nil {
		panic(err)
	}
	w.Err(msgStr)
	w.Close()
}

What did you expect to see?

hello logged to the macOS Console.app

What did you see instead?

Nothing is logged.

I noticed that I can get this working with cgo -

package main

// #include <syslog.h>
// void doLog(int facility, const char *msg) {
//	syslog(facility, "%s", msg);
//}
import "C"

func main() {
	msgStr := `hello`
	C.doLog(C.LOG_ERR|C.LOG_DAEMON, C.CString(msgStr))
}

So syslog is working and this is not a configuration issue. I think the problem is that macOS's logd no longer accepts syslog messages on /var/run/syslog, or perhaps the expected format has changed.

I can see that it's listening:

$ sudo lsof|grep var/run/syslog
launchd       1                  root    3u     unix 0x3a45c3be17aa6ff3          0t0                     /private//var/run/syslog
logd        313                  root    7u     unix 0x3a45c3be17aa6ff3          0t0                     /private//var/run/syslog

But I'm not sure if calling syslog(3) is using some other mechanism to reach logd.

@craig65535
Copy link
Author

This was noted by the Python people: python/cpython#91070

@craig65535 craig65535 changed the title log/syslog: local messages (syslog.New()) do not work on Darwin log/syslog: local messages (syslog.New()) do not work on macOS Monterey/Ventura Mar 26, 2023
@mdempsky mdempsky added the NeedsDecision Feedback is required from experts, contributors, and/or the community before a change can be made. label Mar 27, 2023
@mdempsky mdempsky added this to the Go1.21 milestone Mar 27, 2023
@craig65535
Copy link
Author

FWIW I do have a (terrible) workaround for this that doesn't involve cgo. I exec /usr/bin/logger -p <facility>.<severity> and then feed it messages over stdin. It doesn't tag the messages as coming from my process, but it does get logs into the Console and log store.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help wanted NeedsDecision Feedback is required from experts, contributors, and/or the community before a change can be made. OS-Darwin
Projects
None yet
Development

No branches or pull requests

3 participants