stumpless
2.1.0
|
A C logging library built for high performance and a rich feature set.
Key Features | Download and Build | Basic Usage | Contributing
Stumpless offers a robust set of features to make logging in C faster and easier:
A primary goal of this library is to provide a consistent logging interface to a wide variety of log targets. This means you can focus on defining events and where you want them to go, without finding other SDKs or adding daemons and plugins to get them where you want. Stumpless can write logs to:
Don't see what you need? Create an issue with your request and we'll work it into our roadmap!
Stumpless only requires cmake and a cmake-supported build toolchain (like GCC or Visual Studio) to build. For a system using the standard GNU make toolchain, you can simply do:
Check out the Installation Instructions for more detail on building and installing stumpless in different environments and/or with other toolchains.
The following code snippets show the most common ways to use stumpless.
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 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:
And of course, you can use format specifiers in both functions just as you would with printf
:
If you don't need format specifiers, use one of the _str
variants: it's both faster and safer!
If you want to open a specific target rather than using the default, then just open the target that 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 do this:
Using these functions has the added benefit that they can be removed at compile time by simply defining the 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 stumpless/level to see the full list of severity shorthand functions, or the severity level example to see a complete program in action.
For more detailed examples of the above scenarios, usage of specific target types, how to handle more complicated message structures, and more check out the examples. These include annoted example code files to compile, run, and modify to get you started.
Notice a problem or have a feature request? Just create an issue using one of the templates, and we will respond as quickly as we can. You can also look at the project's Contribution Guidelines for more details on the different ways you can give back to the open source community!
If you want to actually write some code or make an update yourself, take a look at the development guide to get a detailed orientation. There are a few options based on your level of experience and familiarity with making contributions.
The first option is to browse the list of issues that are marked with the label good first issue. These issues are selected to be a small but meaningful amount of work, and include details on the general approach that you can take to complete them. They are a great place to start if you are just looking to test the waters of this project or open source contribution in general.
More experienced developers may prefer to look at the full list of issues on the project, as well as the roadmap. If an item catches your interest, drop a comment in the existing issue or open a new one if it doesn't exist yet and state your intent to work on it so that others will have a way to know it is underway.
Or perhaps you are just looking for a way to say thanks! If that's the case or if there is something that you would prefer to drop me a private message about, please feel free to do so on Twitter with #StumplessLib, or in an email! I'd love to see you share the project with others or just hear your thoughts on it.
If you're curious about how something in stumpless works that isn't explained here, you can check the appropriate section of the documentation, stored in the docs folder of the repository. Folders in the repository contain their own README files that detail what they contain and any other relevant information. If you still can't find an answer, submit an issue or head over to gitter and ask for some help.