You may use blowhole
.
blowhole
is a command-line device that takes a string as an argument and sends it to the unified logging system. It’s supported, in several releaes, from Sierra (10.12) as much as Sonoma (14).
Tips on how to use it
(Examined on macOS Catalina 10.15.5)
Modify the ProgramArguments
array in your .plist
file like this:
<key>ProgramArguments</key>
<array>
<string>/bin/bash</string>
<string>-c</string>
<string>COMMAND OPTIONS 2> >(whereas learn; do /path/to/blowhole -e "$REPLY"; executed) | whereas learn; do /path/to/blowhole -d "$REPLY"; executed</string>
the place COMMAND OPTIONS
is the command you need to execute, adopted by any desired choices.
Right here, I make use of bash
‘s help for redirection (2>
), course of substitution (>()
) and pipelines (|
) to:
- kind out the command’s normal error and normal output
- course of them individually inside two
whereas
loops. The primarywhereas
loop runsblowhole -e
to log normal error with an “Error” degree:
<timestamp> Error <data> blowhole: [co.eclecticlight.blowhole:general] Blowhole: STANDARD ERROR MESSAGES
and the second runs blowhole -d
to log normal output with a “Default” degree:
<timestamp> Default <data> blowhole: [co.eclecticlight.blowhole:general] Blowhole: STANDARD OUTPUT MESSAGES
(Since blowhole
cannot learn from normal enter, we’d like whereas
loops to feed it a line of enter at a time.)
The blowhole: [co.eclecticlight.blowhole:general] Blowhole:
string shouldn’t be configurable, however you possibly can add a prefix of your option to the logged messages. For instance, because you point out offlineimap
in your query:
/path/to/blowhole -d "offlineimap stdout: $REPLY";
and:
/path/to/blowhole -e "offlineimap stderr: $REPLY";
You’ll be able to learn log entries with sudo log present | grep blowhole:normal
or sudo log present | grep offlineimap
, in the event you added the personalized prefix. To learn log entries as they’re generated, in a fashion much like tail -f
, use present stream
as a substitute.
Alternatively, you possibly can wrap the command you need to execute in a shell script in order that blowhole
logs the command’s normal output and error in a method much like above. That is handy if you wish to run some code previous to executing the precise command:
#!/bin/bash
# Add the code you need to execute previous to the precise command right here
COMMAND ARGUMENTS
> >(
whereas learn; do
/path/to/blowhole -d "$REPLY";
executed)
2> >(
whereas learn; do
/path/to/blowhole -e "$REPLY";
executed)
You’ll be able to then configure the ProgramArguments
array of your .plist
file to run the script as a substitute of your command:
<key>ProgramArguments</key>
<array>
<string>/bin/bash</string>
<string>/path/to/script.sh</string>
</array>
The place to get it from
You’ll be able to obtain blowhole
from its product web page or straight with these hyperlinks:
- Blowhole 9: Intel-only for Sierra (10.12) to Catalina (10.15)
- Blowhole 10a: Common binary for Sierra (10.12) to Ventura (13)
- Blowhole 11: Common binary for Huge Sur (11) tp Sonoma (14)
This system is supplied as a signed, hardened and notarized executable (as required by Catalina and later) and as an Installer bundle.