Skip to content

Getting Started

Hugo edited this page Oct 15, 2026 · 2 revisions

Getting Started

Requirements

  • A C++20 compiler with <format> and <source_location>: GCC 13+, Clang 16+, AppleClang 15+, or Visual Studio 2022
  • CMake 3.16 or newer
  • Linux, macOS or Windows

Add the library to a CMake project

FetchContent

include(FetchContent)
FetchContent_Declare(coretrace-logger
  GIT_REPOSITORY https://github.com/CoreTrace/coretrace-log.git
  GIT_TAG        v1.1.1
)
set(CORETRACE_LOGGER_BUILD_EXAMPLES OFF CACHE BOOL "" FORCE)
FetchContent_MakeAvailable(coretrace-logger)

target_link_libraries(my_target PRIVATE coretrace::logger)

Pin a release tag rather than main.

add_subdirectory

add_subdirectory(path/to/coretrace-log)
target_link_libraries(my_target PRIVATE coretrace::logger)

Installed package

git clone https://github.com/CoreTrace/coretrace-log.git
cmake -S coretrace-log -B build -DCMAKE_BUILD_TYPE=Release
cmake --build build
cmake --install build --prefix /usr/local
find_package(coretrace-logger 1.1 REQUIRED)
target_link_libraries(my_target PRIVATE coretrace::logger)

The package declares SameMajorVersion compatibility: a request for 1.1 accepts any later 1.x release.

On a multi-config generator (Visual Studio), pass the same --config to cmake --build and cmake --install. On a single-config generator, set CMAKE_BUILD_TYPE when configuring: cmake --install --config Release only installs the per-config target file for the configured build type.

Build options

Option Default Effect
CORETRACE_LOGGER_BUILD_EXAMPLES ON Builds example/main.cpp
CORETRACE_LOGGER_BUILD_TESTS ON for the top-level project, OFF as a subproject Builds the tests and registers them with CTest

Examples are built by default even when the library is a subproject. Set the option to OFF before FetchContent_MakeAvailable() or add_subdirectory() to skip them.

Build and test from source

cmake -S . -B build -G Ninja
cmake --build build
ctest --test-dir build --output-on-failure

With Visual Studio:

cmake -S . -B build-win -G "Visual Studio 17 2022" -A x64
cmake --build build-win --config Release
ctest --test-dir build-win -C Release --output-on-failure

scripts/build.sh wraps the configure and build steps: --type, --build-dir, --generator, --jobs, --clean and --configure-only.

First program

#include <coretrace/logger.hpp>

int main() {
  using namespace coretrace;

  enable_logging(); // Logging is disabled until this call.
  set_min_level(Level::Debug);

  log(Level::Debug, "starting with {} workers\n", 4);
  log(Level::Warn, Module("net"), "retrying {}\n", "10.0.0.1");
}
|4242| ==ct== [DEBUG] starting with 4 workers
|4242| ==ct== [WARN] (net) retrying 10.0.0.1

Messages are written as given: end them with \n. Next: Configuration.

Clone this wiki locally