How to write to the log from a script

Old command tools still rest in macOS like ghosts. One of the oldest must be logger, once used as a convenient way for scripts to write tagged messages to the log. When macOS switched to using the Unified log in Sierra, over six years ago, Apple modified logger to write to the new log. Whoever did that failed to update its man page, which is still dated 6 June 1993, encouraging us to celebrate its thirtieth birthday this year.

You’ll see what I mean if you run the following command in Terminal, then browse the log and see what’s written there:
logger -i -t "SpecialTag" "This was written by logger"

According to the man page, the -i option should log the process id of the logger process, the -t option should add the tag SpecialTag, and the message This was written by logger should appear in its message field.

What you actually get in the Unified log is just the message, with no tag, as tags aren’t supported by the new log, and there’s no subsystem, making it harder to locate and identify. I fear that six years ago logger died in its sleep, and is now ready for burial.

Fortunately, early in 2017 I wrote a small command tool, blowhole, offering a lot more than logger ever did, and it works splendidly from scripts or anything else that can run a simple command tool. In this case, as an example, the command
blowhole -e "This is a blowhole error."
writes an Error message (option -e) from subsystem co.eclecticlight.blowhole containing the message
Blowhole: This is a blowhole error.

You can find that quickly using a predicate filter for its subsystem, without having to search for process names or text contained in log messages.

blowhole has other options too. You can assign its entries different levels from debug to fault, you can write Signposts rather than regular log entries, and you can even get it to loop through a series of log entries as fast as it can. It’s a Universal binary, notarised, supplied in a convenient Installer package, and runs a treat in Ventura too.

If you write scripts of any kind and want to be able to write messages to the Unified log, you’ll find blowhole, free of course, on its Product Page.

It’s time to let logger rest in its grave.