bash 从 shell 脚本或命令行写入 Mac OS X 控制台日志
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/16818427/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Write to Mac OS X Console logs from shell script or command line
提问by asmeurer
Is there a simple, portable (preferably works with older OS X versions) way to write a message to the Mac OS X Console logs from a shell script?
是否有一种简单的、可移植的(最好适用于较旧的 OS X 版本)从 shell 脚本向 Mac OS X 控制台日志写入消息的方法?
回答by Ian Roberts
syslog -s -l error "message to send"
will log the message as something like
将消息记录为类似
May 29 17:15:09 hostname syslog[22316]: message to send
You can customize things by using -k, which expects a list of alternating keys and values, for example
您可以使用 自定义事物,例如-k,它需要一个交替键和值的列表
syslog -s -k Facility com.apple.console \
Level Error \
Sender MyScript \
Message "script says hello"
would produce
会产生
May 29 17:22:21 hostname MyScript[22343]: script says hello
(setting the Facilityto com.apple.consolemakes it a "console" message, equivalent to stdout output from a double-clicked bundled application, and retrievable using syslog -C)
(将 设置Facility为com.apple.console使其成为“控制台”消息,相当于双击捆绑应用程序的标准输出输出,并可使用 检索syslog -C)
回答by cody
May be you should try the syslogcommand with -s option? See man syslogfor details.
For example sudo syslog -s o.O
也许您应该尝试syslog使用 -s 选项的命令?详情请参阅man syslog。
例如sudo syslog -s o.O

