autotoc_md1966
doc_id: "LOG-GUID-021" doc_title: "Getting Started with Logger System" doc_version: "1.0.0" doc_date: "2026-04-04" doc_status: "Released" project: "logger_system"
category: "GUID"
Language: English | 한국어
Getting Started with Logger System
SSOT: This document is the single source of truth for Getting Started with Logger System.
This guide will help you get started with the Logger System quickly.
Table of Contents
- Requirements
- Installation
- Basic Usage
- Configuration
- Integration with Thread System
Requirements
- C++20 compatible compiler:
- GCC 10+
- Clang 12+
- MSVC 2019+ (Visual Studio 2019 version 16.11+)
- CMake 3.16 or higher
- Operating System:
- Linux (Ubuntu 20.04+, CentOS 8+, etc.)
- macOS 10.15+
- Windows 10+
Installation
Using CMake FetchContent (Recommended)
Add the following to your CMakeLists.txt:
include(FetchContent)
FetchContent_Declare(
LoggerSystem
GIT_REPOSITORY https://github.com/kcenon/logger_system.git
GIT_TAG v0.1.0 # Pin to a specific release tag; do NOT use main
)
FetchContent_MakeAvailable(LoggerSystem)
# Link to your target
target_link_libraries(your_target PRIVATE LoggerSystem::logger)
Building from Source
# Clone the repository
git clone https://github.com/kcenon/logger_system.git
cd logger_system
# Create build directory
mkdir build && cd build
# Configure
cmake .. -DCMAKE_BUILD_TYPE=Release
# Build
cmake --build .
# Install (optional)
sudo cmake --install .
Using as Installed Package
If you've installed the logger system:
find_package(LoggerSystem REQUIRED)
target_link_libraries(your_target PRIVATE LoggerSystem::logger)
Basic Usage
Simple Console Logging
#include <logger_system/logger.h>
#include <logger_system/writers/console_writer.h>
auto logger = std::make_shared<logger_module::logger>();
logger->add_writer(std::make_unique<logger_module::console_writer>());
logger->log(thread_module::log_level::info,
"Application started");
logger->log(thread_module::log_level::warning,
"This is a warning");
logger->log(thread_module::log_level::error,
"An error occurred!");
return 0;
}
Logging with Source Location
Source location is automatically captured in v2.x+ using C++20's std::source_location. You no longer need to pass __FILE__, __LINE__, and __func__ manually.
logger->log(thread_module::log_level::debug,
"Debug information");
#include <kcenon/common/interfaces/logger_interface.h>
logger->log(common::interfaces::log_level::debug,
"Debug with explicit location");
#include <kcenon/common/logging/log_macros.h>
LOG_DEBUG("This includes auto-captured source location");
Note: The legacy API with __FILE__, __LINE__, __func__ is deprecated and will be removed in v3.0.0.
Structured JSON Output
The structured_logger provides JSON/logfmt/plain output. For strict JSON compliance at scale, consider integrating a JSON library (e.g., nlohmann/json):
Alternatively, keep using structured_logger and route JSON output to file/network. When adding a JSON library, prefer compile-time options to keep it optional.
Log Levels
The logger supports six log levels:
enum class log_level {
trace,
debug,
info,
warning,
error,
critical
};
Filtering by Level
logger->set_min_level(thread_module::log_level::info);
logger->log(thread_module::log_level::trace,
"Too detailed");
logger->log(thread_module::log_level::debug,
"Debug info");
logger->log(thread_module::log_level::info,
"Important info");
logger->log(thread_module::log_level::error,
"Error!");
Configuration
Synchronous vs Asynchronous Logging
auto async_logger = std::make_shared<logger_module::logger>(true, 8192);
auto sync_logger = std::make_shared<logger_module::logger>(false);
Multiple Writers
auto console = std::make_unique<logger_module::console_writer>();
logger->add_writer(std::move(console));
class my_writer : public logger_module::base_writer {
void write(thread_module::log_level level,
const std::string& message,
const std::string& file,
int line,
const std::string& function,
const std::chrono::system_clock::time_point& timestamp) override {
}
void flush() override {
}
};
logger->add_writer(std::make_unique<my_writer>());
Windows Notes (Networking)
The network writer/server use POSIX sockets. On Windows, add WinSock initialization and adapt socket calls:
- Call
WSAStartup(MAKEWORD(2,2), &wsaData) before creating sockets and WSACleanup() at shutdown.
- Replace
close(fd) with closesocket(fd) and use appropriate error codes (e.g., WSAGetLastError()).
- Consider a small socket abstraction layer guarded by
#ifdef _WIN32 to keep code portable.
Console Writer Options
auto console = std::make_unique<logger_module::console_writer>(true);
auto console = std::make_unique<logger_module::console_writer>(false, false);
console->set_use_color(false);
Integration with Thread System
Using Service Container
#include <logger_system/logger.h>
#include <logger_system/writers/console_writer.h>
#include <thread_system/interfaces/service_container.h>
#include <thread_system/interfaces/thread_context.h>
#include <thread_system/thread_pool/core/thread_pool.h>
auto logger = std::make_shared<logger_module::logger>();
logger->add_writer(std::make_unique<logger_module::console_writer>());
thread_module::service_container::global()
.register_singleton<thread_module::logger_interface>(
logger);
thread_module::thread_context context;
auto pool = std::make_shared<thread_pool_module::thread_pool>("MyPool", context);
pool->start();
pool->stop();
return 0;
}
Direct Integration
auto logger = std::make_shared<logger_module::logger>();
logger->add_writer(std::make_unique<logger_module::console_writer>());
std::shared_ptr<thread_module::logger_interface> logger_interface =
logger;
auto context = thread_module::thread_context(logger_interface);
Next Steps
- Read the Architecture Overview to understand the system design
- Check the API Reference for detailed documentation
- See Performance Guide for optimization tips
- Learn about Custom Writers for specialized output
Last Updated: 2025-10-20