This commit adds the following changes to pinelog:
- Optional buffer to write the message to prior to writing to the output
stream. This reduces the likelihood of log messages from multiple
threads interleaving due to multiple calls to fputs/fprintf, etc. The
default is to still write directly to the output stream, but the
integrator can add a define of PINELOG_BUFFER_SZ to the CFLAGS, and
this will allow the application to log messages that are shorter than
the above size, including the timestamp, level and backtrace if any.
- Optional module level logging. This allows more fine-grained
debugging, where the application can control the log levels of the
individual modules. By default, when modules are configured, they
default to the global log level, but this can be overridden by the
application.
Prior to this change, pinelog used __FILE__ in the backtrace call.
However, this has a limitation that if used in a build system with
sources in subdirectories and/or a separate build directory, the
relative path to the file is used, giving us a backtrace like this.
../../daemon/x52d_main.c:51
This change checks if the compiler supports the __builtin_strrchr to
compute the file basename at compile time. If the compiler does not
support it, it falls back to using __FILE__ directly. This should not be
an issue on a modern compiler like gcc or clang.
Prior to this change, pinelog relied on an autoconf generated config.h
which checked if the compiler supports __attribute__ with constructor,
destructor and format. However, most modern compilers already have
support for this, and we can use the __has_attribute special operator
instead to check for this at compile time.
By eliminating the need to create a config.h file, it simplifies
integration into other projects that may not have one.