A minimal and thread-safe header-only logging library with zero dependencies.
- Multiple log levels (TRACE, DEBUG, INFO, WARN, ERROR, FATAL).
- Colored console output (ANSI color codes).
- Thread-safe synchronous logger.
- Type-safe formatting.
- Console sink.
- File sink.
- Network sink (TCP/UDP).
- Asynchronous logger with background thread.
- Custom output formatters.
- Custom timestamp formats (ISO8601, RFC3339, etc.).
- Multiple simultaneous sinks.
- Log rotation (size-based and time-based).
- Log level from environment variable
- Source locations macros (file:line).
- Structured logging (JSON).
- Filter by regex/pattern.
- Context tags.
#include <tinylog/sync_logger.hpp>
auto main() -> int
{
tinylog::SyncLogger logger(tinylog::LogLevel::TRACE);
logger.trace("Application starting...");
logger.debug("Loading configuration file from config.yaml...");
logger.info("Server listening on port 8080");
logger.warn("Cache is 80% full");
logger.error("Failed to connect to database");
logger.fatal("Out of memory!");
return 0;
}See examples/ for formatted strings, dynamic log levels, multithreading and more.
include(FetchContent)
FetchContent_Declare(
tinylog
GIT_REPOSITORY https://github.com/abidanBrito/tinylog
GIT_TAG main
)
FetchContent_MakeAvailable(tinylog)
target_link_libraries(your_target PRIVATE tinylog::tinylog)Copy the include/tinylog/ directory to your project, either manually or by running one of the commands below:
Linux/macOS
cp -r include/tinylog /path/to/your/project/include/Windows (Command Prompt)
xcopy /E /I include\tinylog \path\to\your\project\include\tinylogWindows (PowerShell)
Copy-Item -Path "include\tinylog" -Destination "\path\to\your\project\include\tinylog" -RecurseThen add this to your CMakeLists.txt in order to link against tinylog:
add_subdirectory(path/to/tinylog)
target_link_libraries(your_target PRIVATE tinylog::tinylog)Simply copy the include/tinylog/ directory to your project and compile with C++20 and link pthread.
GCC
g++ -std=c++20 -pthread -I./include main.cpp -o appClang
clang++ -std=c++20 -pthread -I./include main.cpp -o appMSVC
cl /std:c++20 /EHsc /I.\include main.cppThis repository is released under the MIT license. See LICENSE for more information.
