Skip to content
/ microlog Public

A lightweight, universal logging library in C. Just two files. Compatible with C++, embedded projects, and most major compilers. Covered by unit tests.

License

Notifications You must be signed in to change notification settings

an-dr/microlog

Repository files navigation

microlog - Extensible and configurable logging library for embedded and desktop applications

License: MIT Latest Tests

main_pic

  • Easy to use - simple API, works out of the box
  • Advanced filtering and log levels per topic or output
  • Thread-safety via external locking injection
  • Customization - only data you need
  • Extensible - add your own features via public API, set of predefined extensions
  • Support for embedded systems static allocation, small size
  • Easy to install two files for copy-paste and support for many build systems
  • For everyone - C and C++ support, works with any compiler, any platform, commercial or open-source use

In the default configuration it looks like this:

Picture 1 - default configuration: no time, long default levels, source location, no topics, no colors

...but in can be very minimalistic :

Picture 2 - short levels, no colors, no time, no source location

... or feature-rich:

Picture 3 - time, custom prefix for MsgID, custom syslog levels, topics, source location, colors

The project is based on the following core principles:

  • Universal for embedded and desktop applications
  • No feature - no code for compilation
  • Shallow learning curve, works out of box
  • No dependencies
  • Two files for core functionality.
  • Extensions as recipes for your own features.

Table of Contents

Quick Start

1. Install

Option 1 - Sources:

  • Download a Source Package from Releases
  • Add sources to your system manually

Option 2 - CMake Package (recommended CMake > 3.15.0):

  • Download a CMake Package from Releases
  • Specify the install location:
    • Specify package storage cmake -B./build -DCMAKE_PREFIX_PATH="~/MyCmakePackages" or
    • Set microlog_DIR variable with path to the package microlog_DIR=~/microlog-1.2.3-cmake
  • Use in your project:
find_package(microlog 1.2.3 REQUIRED)

add_executable(example_package example.cpp)
target_link_libraries(example_package PRIVATE microlog::microlog)

target_compile_definitions(microlog PRIVATE ULOG_BUILD_COLOR=1) # configuration

Option 3 - Meson Package:

  • Download a Meson Package from Releases
  • Copy the content to MyMesonProject/subprojects
  • Add to your dependencies:
add_global_arguments('-DULOG_BUILD_COLOR=1', language: ['cpp', 'c']) # configuration

exe = executable(
    meson.project_name(),
    src,
    include_directories: include,
    dependencies: dependency('microlog'),
)

Option 4 - Meson Wrap File:

  • Download the wrap file from Releases
  • Place microlog.wrap in your MyMesonProject/subprojects/ directory
  • Add to your dependencies as in Option 3

Option 5 - CPM:

include(cpm/CPM.cmake)
CPMAddPackage("gh:an-dr/[email protected]")

target_link_libraries(${PROJECT_NAME} PUBLIC microlog::microlog)
target_compile_definitions( microlog
        INTERFACE
        ULOG_BUILD_COLOR=1) # configuration

2. Use

#include "ulog.h"

int main() {
    ulog_info("Hello, World");
    return 0;
}

Output:

INFO  src/main.cpp:4: Hello, World

3. Extend

Add missing functionalities via API or use predefined extensions. See Extensions documentation.

Advanced Usage

User Manual in doc/features.md - detailed information about the available features.

Extensions - Optional add-ons that use only the public API to enhance functionality.

See the example for more features in action: example/main.cpp.

Contributing

Contributions are welcome! Please read the CONTRIBUTING.md for details, I tried to keep it simple.

Changelog

See CHANGELOG.md for details.

License

This library is free software; you can redistribute it and/or modify it under the terms of the MIT license. See LICENSE for details.

Credits

Based on https://github.com/rxi/log.c.git

About

A lightweight, universal logging library in C. Just two files. Compatible with C++, embedded projects, and most major compilers. Covered by unit tests.

Topics

Resources

License

Contributing

Stars

Watchers

Forks

Contributors 6