stumpless

a C logging library built for performance and features

451
337
C

Stumpless logo

A C logging library built for high performance and a rich feature set.

Linux Builds
Windows Builds
Mac Builds
Coverage Report
SonarCloud Status
Gitter
Apache 2.0 License
Contributor Covenant

็ฎ€ไฝ“ไธญๆ–‡

Key Features |
Build and Install |
Basic Usage |
Contributing

Key Features

Stumpless has lots of features that make logging in C fast and easy:

  • log to lots of things like Splunk, rsyslog,
    journald, the Windows Event Log, sqlite, and more!
  • structured and unstructured logging to suit your needs
  • builds on Linux, Windows, Mac, FreeBSD, MinGW, MSYS2, Cygwin, DOS, and more!
  • thread safe
  • can be adjusted or removed during compilation for zero runtime cost
  • localized for multiple languages ๐Ÿ‡ฆ๐Ÿ‡ฑ ๐Ÿ‡ง๐Ÿ‡ท ๐Ÿ‡ง๐Ÿ‡ฌ ๐Ÿ‡จ๐Ÿ‡ณ ๐Ÿ‡จ๐Ÿ‡ฟ ๐Ÿ‡ฉ๐Ÿ‡ช ๐Ÿ‡ฉ๐Ÿ‡ฐ ๐Ÿ‡ช๐Ÿ‡ธ ๐Ÿ‡ซ๐Ÿ‡ท ๐Ÿ‡ฌ๐Ÿ‡ท ๐Ÿ‡ญ๐Ÿ‡บ ๐Ÿ‡ฎ๐Ÿ‡ณ ๐Ÿ‡ฎ๐Ÿ‡ฑ ๐Ÿ‡ฎ๐Ÿ‡น
    ๐Ÿ‡ฏ๐Ÿ‡ต ๐Ÿ‡ฐ๐Ÿ‡ช ๐Ÿ‡ฐ๐Ÿ‡ท ๐Ÿ‡ต๐Ÿ‡ฑ ๐Ÿ‡ธ๐Ÿ‡ฐ ๐Ÿ‡ฑ๐Ÿ‡ฐ ๐Ÿ‡ธ๐Ÿ‡ช ๐Ÿ‡น๐Ÿ‡ท ๐Ÿ‡บ๐Ÿ‡ธ
    (add yours!)
  • easy-access
    documentation,
    examples,
    and support.

What can it log to?

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:

  • Simple character buffers
  • Files and streams
  • Unix sockets (such as a local syslog daemon)
  • Network servers (IPv4 or IPv6, TCP or UDP)
  • Systemd Journald service
  • Sqlite3 databases
  • Windows Event Log
  • Custom functions, for whatever else you may need!

Donโ€™t see what you need? Create an
issue
with your request and weโ€™ll work it into our
roadmap!

Quick Build and Install

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:

# cloning the latest version of the source tree
git clone [email protected]:goatshriek/stumpless.git

# creating a new build directory
mkdir build
cd build

# configuring the new build
cmake ../stumpless

# building stumpless (with 4 threads - adjust as desired)
make -j 4 all

# install the library (you probably need sudo to do this)
sudo make install

Check out the Installation Instructions for more detail on
building and installing stumpless in different environments and/or with other
toolchains.

Basic Usage

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're used to doing this:
syslog( LOG_INFO | LOG_USER, "My message #%d", count );

// then you can start by changing to this:
stumplog( LOG_INFO | LOG_USER, "My message #%d", count );

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:

stump( "Login attempt failure #%d for user %s", count, username );

If you donโ€™t need format specifiers, use one of the _str variants:
itโ€™s both faster and safer!

stump_str( "Login failure! See structured data for info." );

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:

target = stumpless_open_file_target( "example.log" );

// uses the last opened target by default
stump( "Login attempt failure #%d for user %s", count, username );

Sending messages over the network to something like Splunk or rsyslog is just
as easy:

target = stumpless_open_udp4_target( "send-to-splunk-example",
                                     "mylogserver.com" ); // or use an IP
stump( "Login attempt failure #%d for user %s", count, username );

If you have multiple targets, you can send messages to a chosen target like
this:

stumpless_add_message( target,
                       "Login attempt failure #%d for user %s",
                       count,
                       username );

Severity Shorthand

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:

stump_i( "this gets logged as an info message" );

And if you want to also see source file, line number, and function name info in
each message you can use _t (the โ€˜tโ€™ is for trace):

stump_t( "this includes source info" );

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.

// be sure to define this before stumpless.h gets included
#define STUMPLESS_ENABLE_UPTO_INFO

// ...

// this log will go through just fine
stump_i( "I'm doing that thing you asked" );

// this debugging message is completely removed: no runtime impact whatsoever
stump_d( "DEBUG info: %d, %d, %s", thing_1, thing_2, stringy_thingy );

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.

Even more examples

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.

Contributing

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.

Documentation and Community

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.
Folders in the repository contain their own README files that detail what they
contain and any other relevant information. The documentation for each function
is also hosted on the
project website, for both the C
library as well as the other language bindings like C++.

Stumpless also includes documentation in local installations in the form of
man pages. Once youโ€™ve installed the library, you can check the documentation
for any header file (and the functions it contains) by running man with the
name of the header with directories replaced with underscores, for example
man stumpless_log.h to see documentation for functions that log simple string
messages.

There are also plenty of ways that you can reach out to the project team and
broader community for support.

  • Issues and
    discussions on Github
    are good ways to get a response if you have a specific question or
    suggestion.
  • There is a persistent chat on gitter
    where you can find announcements and ask questions.
  • News about the project are typically announced on Twitter as well by
    goatshriek, using
    #StumplessLib.
  • You can reach the primary maintainer via email
    if you want private communication. This is the preferred method for
    notifying
    us of security issues with the project, so that we can address them as
    quickly as possible to reduce the risk of abuse.