英文:
golang syslog failure: Unix syslog delivery error
问题
我正在运行OSX Mavericks 10.9.2。我正在尝试将我的Revel应用程序日志记录到syslog。我的代码在这一行出错:
sysLog, err := syslog.New(syslog.LOG_NOTICE|syslog.LOG_LOCAL0, "myApp")
出现以下错误:
Unix syslog传递错误
syslog在我的机器上肯定是运行的。可能的问题是什么?
英文:
I'm on OSX running Mavericks 10.9.2. I'm trying to get my Revel app logging to syslog. My code is failing on this line:
sysLog, err := syslog.New(syslog.LOG_NOTICE|syslog.LOG_LOCAL0, "myApp")
with this error:
Unix syslog delivery error
Syslog is definitely running on my machine. What could be the problem?
答案1
得分: 2
验证syslog是否正在运行,否则启用它。
$ ps -aux | grep syslog
root 11703 0.0 0.4 14424 1992 - IsJ 9:17AM 0:00.01 /usr/sbin/syslogd -ss
现在验证syslog是否在预期的本地地址上运行。log/syslog软件包会在/var/run/syslog或/dev/log中查找syslog。如果在那里找不到它,你会看到"Unix syslog delivery error",参考链接:http://golang.org/src/pkg/log/syslog/syslog_unix.go。
使用sockstat命令找到syslog的本地地址
$sockstat
USER COMMAND PID FD PROTO LOCAL ADDRESS FOREIGN ADDRESS
root login 12104 3 dgram -> /var/run/logpriv
root login 11791 3 dgram -> /var/run/logpriv
root cron 11754 4 dgram -> /var/run/logpriv
root syslogd 11703 4 dgram /var/run/log
root syslogd 11703 5 dgram /var/run/logpriv
在上述情况中,syslog正在/var/run/log上运行。因此,我创建了一个从/var/run/log到/var/log/syslog的符号链接,错误消失了。
$ln -sf /var/run/log /var/run/syslog
英文:
Verify syslog is running or else enable it.
$ ps -aux | grep syslog
root 11703 0.0 0.4 14424 1992 - IsJ 9:17AM 0:00.01 /usr/sbin/syslogd -ss
Now verify syslog is running in the expected local address. The log/syslog package looks for syslog in /var/run/syslog or /dev/log. If it does not find it there, you see the "Unix syslog delivery error" as per http://golang.org/src/pkg/log/syslog/syslog_unix.go.
To find the local address of syslog use the sockstat command
$sockstat
USER COMMAND PID FD PROTO LOCAL ADDRESS FOREIGN ADDRESS
root login 12104 3 dgram -> /var/run/logpriv
root login 11791 3 dgram -> /var/run/logpriv
root cron 11754 4 dgram -> /var/run/logpriv
root syslogd 11703 4 dgram /var/run/log
root syslogd 11703 5 dgram /var/run/logpriv
In above case, syslog is running at /var/run/log. So, I created a symlink from /var/run/log to /var/log/syslog and the error goes away.
$ln -sf /var/run/log /var/run/syslog
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论