kardianos / service

Run go programs as a service on major platforms.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

System logs do not work on macOS 12

deluan opened this issue · comments

Looks like Apple changed the way the syslog daemon receives log messages, causing all Go programs to not log anything to syslog when using the log/syslog package.

The current workaround is to use CGO and call the syslog() system call.

Are you open to receive a PR that implements the syslog for darwin like that? It could be disabled by simply setting CGO=0, which would revert to the current behaviour, i.e. not working :(

Let me know if you have other possible solutions for this. Thanks!

As I mentioned in the linked bug report, I do have a (bad) workaround for when CGO is not desired, and I'll describe it here in case you find it useful.

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. Note also that the facility seems to be ignored, and all messages going to logger will be logged with the severity given when it was launched. You can work around this in turn by starting separate logger processes for debug, info and notice (notice and higher severity messages like error all appear in the Console as default-level).

One thing I had to do was exec logger into a new process group so it wouldn't be affected by the parent process receiving a ctrl-C. This allowed me to catch SIGINT in my process and continue logging.