README.rst 1.97 KB
Newer Older
Ingo Heimbach's avatar
Ingo Heimbach committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61
Simple C++ Logger
#################


Overview
========

This project provides a simple C++ logger class and API. It supports different logging levels and colorized logging
output. Logging messages that do not conform to the desired display logging level are filtered in the preprocessor
stage and do not affect the program runtime. Therefore, you can add as many logging messages as you want without
affecting cpu or memory usage of the production version of your software.

Currently, Linux and macOS are supported. It is not tested on Windows yet.


Usage
=====

Just add ``logger.cpp`` and ``logger.hpp`` to your project files; they have no dependencies to other libraries. Then
you can use the global default logger by calling:

.. code-block:: cpp

   logger(DEBUG, << "my logging output of variable x" << x << std::endl);

You can output every variable that can be shifted ``<<`` into a ``std::ostream`` object like ``std::cout`` or
``std::cerr``.

Currently, 5 levels of logging output are supported. The levels can be enabled or disabled step-by-step to increase or
decrease the verbosity of the program:

-   ``DEBUG``
-   ``INFO``
-   ``WARNING``
-   ``ERROR``
-   ``CRITICAL``

Each logging level is displayed in a different color.

The displayed logging levels can be controlled by a ``DEFAULT_LOG_LEVEL`` macro. If it is not set it defaults to
``DEBUG`` in a debug environment (``NDEBUG`` macro not set). If ``NDEBUG`` is set, the default logging level is
``WARNING``. The logger can be disabled completely by setting an ``NLOG`` macro. The chosen log level automatically
includes log levels that are less verbose. For example, if ``WARNING`` is set, ``ERROR`` and ``CRITICAL`` logging
messages are also printed to screen.


Example
=======

For a small demonstration, you can compile and execute the test program included in the ``src/`` directory by
entering:

.. code-block:: bash

    make
    ./test


You should get the following output:

.. image:: http://iffwww/pub/media/simple_cpp_logger.gif