Writes, reviews, and fixes C++ code using the Quill v14 asynchronous logging library. Migrates from spdlog, glog, fmtlog, Boost.Log, NanoLog, printf, or iostream logging.
Ships in quill. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description: Claude knows it exists.
SKILL.md joins the conversation and stays.
Read when SKILL.md points to them.
Header-only asynchronous C++17 logging: a log call copies its arguments into the calling thread's
lock-free queue, and one backend thread formats and writes them. Namespace quill; the bundled
{fmt} is fmtquill.
Do not write Quill from memory. The API changed in v4, v7, v10 and v14, and models recall the
old forms (quill::start(), quill::get_logger(), handlers). Use the forms below. A project that
pins an older release (GIT_TAG, vcpkg.json, Conan) or whose QUILL_VERSION_MAJOR is missing or
below 14 uses an older Quill: read references/stale-api.md and keep its
version unless asked to upgrade.
Search the project for Backend::start first and reuse its setup library, loggers, macros and
FrontendImpl<...> aliases. New setup code in a project with more than one .cpp follows these
two rules; name and arrange the files to fit the project. When existing code breaks them, recommend
the change and why (compile time, one place to configure), and restructure only if the user agrees:
quill/Backend.h, quill/Frontend.h and quill/sinks/*.h, the
slow headers to compile. Static keeps one copy of Quill's state, and on Linux a log call in an
executable needs no TLS lookup,
which a call compiled into a shared library has: recommend it also where the project uses shared
libraries. Only when the user asks or the project requires it, build the setup library as the
one shared library that owns Quill:
references/setup.md. Never link the static one
into several shared modules.quill/std/ headers of the STL
types they log. The logging header includes only quill/Logger.h and quill/LogMacros.h
(quill/LogFunctions.h for quill::info()). Never put the setup headers in a header.One way, when the project has no setup yet:
// file: app_log.h
#pragma once
#include "quill/LogMacros.h"
#include "quill/Logger.h"
namespace app
{
void init_logging(char const* log_file); // call once, first thing in main()
extern quill::Logger* logger; // valid after init_logging()
} // namespace app
// file: app_log.cpp
#include "app_log.h"
#include "quill/Backend.h"
#include "quill/Frontend.h"
#include "quill/sinks/ConsoleSink.h"
#include "quill/sinks/FileSink.h"
namespace app
{
quill::Logger* logger{nullptr};
void init_logging(char const* log_file)
{
quill::Backend::start(); // once per process; a normal exit stops it and writes what is queued
auto console = quill::Frontend::create_or_get_sink<quill::ConsoleSink>("console");
auto file = quill::Frontend::create_or_get_sink<quill::FileSink>(log_file); // appends
logger = quill::Frontend::create_or_get_logger(
"app", {console, file},
quill::PatternFormatterOptions{
"%(time) [%(thread_id)] %(short_source_location:<28) %(log_level:<9) %(logger:<12) %(message)%(mdc)",
"%Y-%m-%d %H:%M:%S.%Qus", quill::Timezone::GmtTime});
}
} // namespace app
// file: main.cpp
#include "app_log.h"
int main()
{
app::init_logging("app.log");
LOG_INFO(app::logger, "Listening on port {}", 8080);
}
add_library(app_log STATIC app_log.cpp)
target_compile_features(app_log PUBLIC cxx_std_17)
target_include_directories(app_log PUBLIC ${CMAKE_CURRENT_SOURCE_DIR})
target_link_libraries(app_log PUBLIC quill::quill)
target_link_libraries(app PRIVATE app_log) # every target that logs
.cpp: put the body of init_logging() at the top of main().quill/SimpleSetup.h and quill/LogMacros.h, then quill::simple_logger()
(stdout), simple_logger("stderr") or simple_logger("app.log"), which starts the backend.quill::quill, or -std=c++17 -I<quill>/include -pthread; MSVC
/std:c++17 /EHsc /I<quill>\include.<LEVEL> is TRACE_L3 (most verbose), TRACE_L2, TRACE_L1, DEBUG, INFO, NOTICE,
WARNING, ERROR or CRITICAL. A logger starts at Info:
logger->set_log_level(quill::LogLevel::Debug).
| Statement | Result |
|---|---|
LOG_INFO(logger, "order {} px {:.2f}", id, px); | {fmt} syntax, formatted on the backend thread |
LOGV_INFO(logger, "fill", id, px); | fill [id: 7, px: 1.5] |
LOGJ_INFO(logger, "fill", id, px); | fields id and px in JSON sinks, fill 7, 1.5 as text |
LOG_WARNING_LIMIT(std::chrono::seconds{1}, logger, "slow {}", ms); | at most once per interval, per call site and thread |
LOG_DEBUG_LIMIT_EVERY_N(100, logger, "tick {}", n); | every 100th call |
LOG_INFO_TAGS(logger, TAGS("net"), "connected"); | tags, printed by %(tags) |
LOG_DYNAMIC(logger, level, "text {}", x); | level is a run-time quill::LogLevel |
quill::info(logger, "text {}", x); | no macro (quill/LogFunctions.h); arguments are evaluated even when the level is off |
| Type | Needs |
|---|---|
Arithmetic, bool, char, std::string, std::string_view, char const*, char[N], void const* | nothing; the call copies strings, so temporaries are safe |
| Enum | format_as(E) in the enum's namespace, or a cast at the call |
std::vector, std::map, std::optional, std::chrono types and other STL types | #include "quill/std/<Type>.h" for each type in the nesting (Vector.h, Map.h, Optional.h, Pair.h, Chrono.h, ...) |
| Your type that owns its data | fmtquill::formatter<T> or format_as(T), plus template <> struct quill::Codec<T> : quill::DeferredFormatCodec<T> {}; (quill/DeferredFormatCodec.h) |
Your type with pointer, reference or std::string_view members | the same with quill::DirectFormatCodec<T> (quill/DirectFormatCodec.h), which formats on the calling thread. A DeferredFormatCodec copies the object and the backend formats the copy later, when such members dangle |
Your type with only operator<< | QUILL_LOGGABLE_DEFERRED_FORMAT(T) or QUILL_LOGGABLE_DIRECT_FORMAT(T) (quill/HelperMacros.h) |
T*, smart pointers, std::thread::id, exceptions | not loggable: pass static_cast<void const*>(p), *p, e.what() |
| Decision | Default | Change it when |
|---|---|---|
| Full queue | grows from 128 KiB per thread to 2 GiB, then blocks | a log call must never block (BoundedDropping), or memory must stay fixed (BoundedBlocking) |
| Backend thread | sleeps 500 us when idle (10 ms on Android; on Windows until the timer tick, ~15.6 ms), not pinned | shorter delay to the sinks: sleep_duration = 0 and cpu_affinity |
| Flushing | when the backend is idle, at most every 200 ms | the output is read right after: logger->flush_log() |
| Crashes | queued records are lost | start the backend with quill::SignalHandlerOptions |
| Clock | TSC | exact wall time, tests, simulated time |
| Loggers | one | a level, name or file per subsystem |
| Unused levels | checked at run time | compile them out: QUILL_COMPILE_ACTIVE_LOG_LEVEL |
Details: the first five in references/runtime.md, the last two in setup.md.
quill::Backend::start() runs. One call per process.quill/Backend.h:
otherwise quill::v14::detail::get_scoped_thread_context_impl is undefined (MSVC LNK2019).quill::Logger*. create_or_get_logger
and create_or_get_sink return an existing name unchanged, ignoring the new arguments (with
RTTI, a sink type the existing sink does not derive from throws). A logger's sinks, pattern and
clock never change: Frontend::remove_logger_blocking(logger) while the backend runs, then
create it again.Logger* crashes.{}. %d is printed as it is. They are checked on the backend,
not by the compiler: a mismatch prints [Could not format log statement ...] at run time.Missing Codec for Type means the argument needs a row of the Arguments table;
type_is_unformattable_for means its formatter or format_as is missing.static with a destructor that a sink or formatter uses must exist before Backend::start():
the drain at exit runs after the destructors of statics constructed later, and on Windows one
first initialised during that drain hangs the exit.FrontendOptions type per program. Custom options derive from quill::FrontendOptions;
files that log then use quill::LoggerImpl<Options>, and only the setup sources
quill::FrontendImpl<Options>, which needs quill/Frontend.h.flush_log() and remove_logger_blocking() wait for the backend. Called with no backend running
they return at once, the removal only requested. Never call them from a sink, filter,
error_notifier or the thread that polls a ManualBackendWorker: they throw, or hang.fork(), start the backend
after the fork, in each process.Invalid format pattern to stderr, and that logger then writes nothing.char or user-type argument, bytes outside printable ASCII, tab, CR
and LF print as \xNN unless backend_options.check_printable_char = {}.<syslog.h> and other libraries define LOG_INFO, LOG_DEBUG, LOG_WARNING. In such files
define QUILL_DISABLE_NON_PREFIXED_MACROS and write QUILL_LOG_INFO(...).flush_log().| Do not write | Write |
|---|---|
#include "quill/Quill.h" | the logging header of the setup above |
quill::start() | quill::Backend::start() |
quill::Config, quill::configure(cfg) | quill::BackendOptions passed to Backend::start() |
quill::get_logger(), quill::create_logger() | quill::Frontend::create_or_get_logger("name", sink); there is no root logger |
quill::stdout_handler(), quill::file_handler(), Handler | Frontend::create_or_get_sink<quill::ConsoleSink>("id"), <quill::FileSink>("path") |
handler->set_pattern(...) | quill::PatternFormatterOptions{...} when creating the logger |
quill::flush() | logger->flush_log() |
Backend::start_with_signal_handler<...>() | Backend::start<quill::FrontendOptions>(options, quill::SignalHandlerOptions{}) |
a quill::ClockSourceType or &clock argument | quill::ClockSource::system(), quill::ClockSource::custom(clock) |
write_log(MacroMetadata const*, uint64_t, ...) in a sink | write_log(quill::LogRecord const& record) |
LOG_WARN, LOG_TRACE, LOG_FATAL, LOG_INFO_WITH_TAGS, LOG_INFO_CFORMAT | LOG_WARNING, LOG_TRACE_L1, LOG_CRITICAL, LOG_INFO_TAGS, LOG_INFO with {} |
fmt::formatter<T> or std::formatter<T> for a logged type | fmtquill::formatter<T> |
quill::loglevel_from_string | quill::log_level_from_string |
Read the one file that matches the task.
| File | Read it when |
|---|---|
| setup.md | adding Quill to a build, the setup library's details, several loggers, compile definitions, the C++20 module, shared libraries and DLLs, Windows and MSVC |
| types.md | an argument is an STL type, an enum or a class, or a codec or formatter error appears |
| output.md | choosing or configuring sinks, rotation, JSON, filters, a custom sink, the line pattern |
| runtime.md | queues, FrontendOptions, BackendOptions, performance, flushing, shutdown, signals, fork(), clocks, unit tests |
| features.md | named arguments, rate limits, tags, MDC, backtrace, the function API, records from another API |
| data-files.md | binary records, pcap captures, CSV files, metrics |
| stale-api.md | code or an example does not match this skill, or Quill is being upgraded |
| migrate.md | replacing another logging library; it names the file with the mapping for each one |
Everything else is in the documentation: https://quillcpp.readthedocs.io/llms.txt lists the pages and https://quillcpp.readthedocs.io/llms-full.txt holds them in one file. Each option is also documented in the header that declares it.
references/data-files.md (opens in a new tab)references/features.md (opens in a new tab)references/migrate-fmtlog-nanolog.md (opens in a new tab)references/migrate-glog-boost.md (opens in a new tab)references/migrate-printf-iostream.md (opens in a new tab)references/migrate-spdlog.md (opens in a new tab)references/migrate.md (opens in a new tab)references/output.md (opens in a new tab)references/runtime.md (opens in a new tab)references/setup.md (opens in a new tab)references/stale-api.md (opens in a new tab)references/types.md (opens in a new tab)What SKILL.md sets; muted values are Claude Code's defaults
/quill:quillfrom quill
npx claudepluginhub odygrd/quill --plugin quillOther plugins' skills for the same job