stumpless 2.2.0
|
Stumpless is a C logging library built for high performance and a rich feature set.
The simplest way to get started is to use the stumplog
function as a direct replacement for the standard library's syslog
function:
If you haven't opened a target, this will log messages to the default target for the platform: on Linux this is /dev/log
, on a Mac system this will be /var/run/syslog
, and on a Windows machine it is the Windows Event Log. If you open a target or even a few before calling stumplog
, then logs will be sent to the most recently opened target.
If you want an even shorter function call, you can use the stump() function to send a message to the current target. You can also use format specifiers just as you would with printf
.
If you don't need format specifiers, use one of the _str
variants such as stump_str(): it's both faster and safer!
If you want to open a specific target rather than using the default, then just open the one you need and start sending messages. For example, to log to a file named example.log
Sending messages over the network to something like Splunk or rsyslog is just as easy:
If you have multiple targets, you can send messages to a chosen target like this:
It's common to specify severity levels directly in logging calls, so stumpless provides some macro functions to make this less verbose and more efficient. For example, to log messages with a severity of INFO, you can do this:
And if you want to also see source file, line number, and function name info in each message you can use stump_t() (the 't' is for trace):
Using these functions has the added benefit that they can be removed at compile time by simply defining the proper STUMPLESS_ENABLE_UPTO
or STUMPLESS_DISABLE_DOWNTO
symbols. This makes it easy to change logging levels between builds, for example to have prod and debug versions without differences in their source code.
Check out the headers in the stumpless/level include directory named after a severity level such as alert.h to see the full list of severity shorthand functions, or severity_level_example.c to see a complete program in action.