Write to Mac OS X Console logs from shell script or command line
Solution 1
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
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 Facility
to com.apple.console
makes it a "console" message, equivalent to stdout output from a double-clicked bundled application, and retrievable using syslog -C
)
Solution 2
May be you should try the syslog
command with -s option? See man syslog
for details.
For example sudo syslog -s o.O
asmeurer
I am a software developer at Quansight, and am also the lead developer for the SymPy project. Unless otherwise noted, all my questions and answers on StackExchange, including code snippets, are released under Creative Commons CC0 (public domain).
Updated on June 15, 2022Comments
-
asmeurer almost 2 years
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?