flog
is a command-line tool for sending log messages to Apple's unified logging system and is primarily intended for use in scripts.
Why not use
logger(1)
?
logger
doesn't support the full set of log levels offered by Apple's unified logging system, and it lacks support for subsystem and category strings. flog
uses the C language APIs for the unified logging system and supports both.
Install with Homebrew:
brew install marcransome/tap/flog
To log a message using the default
log level:
flog '<message>'
Optionally specify a subsystem and category using the -s, --subsystem
and -c, --category
options:
flog -s uk.co.fidgetbox -c general 'informational message'
Override the default log level using the -l, --level
option and one of the values info
, debug
, error
or fault
:
flog -l fault -s uk.co.fidgetbox -c general 'unrecoverable failure'
flog
can also read the log message from the standard input stream using a pipe:
./some-script | flog -l info
Or the log message can be read from a file using shell redirection:
flog < /var/log/some-script.log
Use the -a, --append
option to also append the log message to a file (creating the file if necessary):
flog -a /var/log/some-script.log -l fault -s uk.co.fidgetbox -c general 'unrecoverable failure'
Warning
Log message strings are public by default and can be read using the log(1)
command or Console app. To mark a message as private add the -p|--private
option to the command. Doing so will redact the message string, which will be shown as '<private>'
when accessed using the methods previously mentioned. Device Management Profiles can be used to grant access to private log messages.
Refer to the log(1)
man page provided on macOS-based systems for extensive documentation on how to access system wide log messages, or alternatively use the Console app.
Here's an example log stream in Console, filtered by subsystem name, showing messages generated by flog
:
And here's a similar log stream viewed with Apple's log(1)
command:
flog
is written in C and requires a suitable compiler and additional tools to build from source. The just command runner is used to manage the development and release process, which functions in a similar manner to make
. For an overview of the available recipes and their usage run just --list
.
- macOS
11.x
(Big Sur) or later - A C17 compiler
- CMake version
>=3.22
- The just command runner
pkg-config
version>=0.29.2
libpopt
version>=1.19
libcmocka
version>=1.1.7
- Pandoc (if building the
man
page)
To perform a development build from the project directory:
just build
The resulting flog
binary will be output to a build/debug/bin
directory and test targets to build/debug/test
.
To build and execute all test targets:
just test
Alternatively, invoke individual test targets directly from the build/debug/test
directory. All test target files begin with the prefix test_
followed by the name of the source file under test.
To build the man page:
just man
The flog.1
man page is output to the man
directory and is converted from the source file man/flog.1.md
using Pandoc.
- Trunk icon made by Freepik from www.flaticon.com
flog
is provided under the terms of the MIT License.
Email me at [email protected] or create an issue.