Skip to content

BringAuto logger library - simple logging abstraction

License

Notifications You must be signed in to change notification settings

bringauto/ba-logger

Repository files navigation

BringAuto Logger Library

BringAuto Logger Library provides a robust and stable API for logging.

The library serves as a consistent API to provide access to different logging libraries, formats, and technologies.

This library consists of header files (.hpp) and multiple implementations. To use the library compile it with your desired implementation, install it (or create a package) and follow the instructions in the Usage section.

Requirements

Before building the library, ensure the following dependencies are installed on your host system:

Build Instructions

To build the library, follow these steps:

mkdir -p _build && cd _build
cmake .. -DCMAKE_INSTALL_PREFIX=<path_where_to_install> -DLIB_TYPE=SPDLOG -DCMAKE_BUILD_TYPE=Release [-DCMLIB_DIR=<path_to_cmlib_dir>]
make -j 8

Other configuration options

  • BRINGAUTO_SYSTEM_DEP=[ON|OFF] - set the variable to ON if the system installed dependencies should be used instead of precompiled ones

Environment Variable

If CMLIB is installed and the CMLIB_DIR environment variable is set, you can omit the -DCMLIB_DIR=<path_to_cmlib_dir> option.

Implementations

Specify the logging implementation type with the -DLIB_TYPE=<TYPE> option. Supported types are:

  • DUMMY: For testing purposes; outputs log messages to the console.
  • SPDLOG: Utilizes the spdlog logging library.

Example Application

To build the example application, enable the BRINGAUTO_SAMPLES option in CMake:

cmake .. -DBRINGAUTO_SAMPLES=ON

The executable for the example application will be located in the ./_build/example/ directory.

Running Tests

To build and run tests, use the following options:

  • Build Tests: Use the flag -DBRINGAUTO_TESTS=ON. Test executables will be located in the ./_build/tests/ directory.

To execute the tests, run:

ctest .

from within the _build directory after configuring with -DBRINGAUTO_TESTS=ON.

Usage

To integrate the library into your project:

  1. Generate a Package: Use the cpack command to create a package.

  2. Install the Package: Install the package on your system.

  3. Include in CMake:

    FIND_PACKAGE(libbringauto_logger)
    TARGET_LINK_LIBRARIES(<target> bringauto_logger::bringauto_logger)
  4. Initialize Logger:

    • Call Logger::addSink() with the desired sink and parameters.
    • Call Logger::init() to finalize the setup.
    • After initialization, you can use the logging functions. Refer to the example application for detailed usage.

Installation

To install the library, enable the BRINGAUTO_INSTALL option in CMake:

cmake .. -DBRINGAUTO_INSTALL=ON

To create a package, use the BRINGAUTO_PACKAGE option and rename the package to follow our naming convention: <packagename>_<version>_<architecture>-<distro>.<extension>. For example: libbringauto_logger_1.5.01_amd64-ubuntu2004.zip.