Repository navigation
Release v2.0.0
Changes
Three user-facing additions: log lines you can lay out yourself, runtime statistics for the internal queues, and the producing thread id. Rendering the built-in layout also got 47% faster.
- Breaking changes. All three are in the custom-sink API or the shared-memory wire format. Code that only calls
LOG_*and uses the built-in sinks is unaffected and needs no changesformat_log_entry()is now a single sharedISinkmethod returning astd::string_viewinto a buffer the sink reuses, rather than astd::stringthatConsoleSinkandFileSinkeach implemented separately. Copy the view if you need it past the next call on that sink- Coloring moved out of
ConsoleSink::get_color_code()/get_reset_code()and into optional arguments toformat_log_entry(), so a sink now opts into escape codes rather than inheriting them. Omit them and%^/%$render as nothing LogEntrygained a thread id field, so shared-memory producers and collectors must be built from the same major version. A 1.3.0 peer cannot share a segment with a 2.0.0 one
- Custom log line layouts.
set_pattern()replaces the fixed header with one of your own, using the same flags as spdlogLogger::instance().set_pattern("%T.%e %^%-5l%$ %-20@ %v")applies to every sink, including sinks added later. A single sink can override it throughISink::set_pattern(), andLogConfig::patternsets it atinit()- Beyond the spdlog set:
%k(producer tag),%q(the sink's configuredTimestampFormatter) and%+(the built-in layout, byte for byte) - A flag takes an optional minimum width, and a leading
-left-aligns it, which is what makes columns line up. A field wider than its width is never truncated - A pattern is parsed once inside
set_pattern()into a flat op list, so a line costs no parsing and no allocation beyond the message itself - nostrftime, noput_time, no locale on the path. The built-in layout went from 291 to 155 ns/line, and a pattern pays only for the fields it actually names: one that renders neither the message nor a level skips thestd::formatpass entirely
- Runtime statistics. Opt in with
config.enable_stats = trueto see the queues backing up before it costs you a log line- A background thread publishes throughput, queue fullness and drop counts. Read them live with
Logger::stats_snapshot(), or setstats_fileto append a CSV row per interval, rolled to<stem>.1.csvatstats_max_file_size - Fullness is a gauge, so a burst that fills the queue and drains between two rows would be invisible. The gauges are sampled every
stats_sample_interval_msand each row reports the interval's peak -entry_queue_pct_maxis the field to alert on, withsample_countshowing the fidelity behind it - Your logging threads pay nothing either way: the figures come from cursors the queues already maintain. The one added cost is two cursor reads per drained batch on the writer thread
- New
statistics_exampledemonstrates it under load
- A background thread publishes throughput, queue fullness and drop counts. Read them live with
- Thread id capture.
%trenders the id of the thread that made theLOG_*call, not the writer thread that formatted it - the real OS thread id, as a debugger ortop -Hshows it, resolved once per thread- The
LogEntryfield is reserved in every build, so processes sharing a segment need not agree on the setting. Build with-DSLICK_LOGGER_ENABLE_THREAD_ID=OFFto drop the per-call capture and%t; entries then carry thread id 0 and the layout is unchanged
- The
ISink::format_log_entry()is protected and available to custom sinks, so one that renders a whole line honorsset_pattern()for free rather than reimplementing the layout
Downloads
The library is header-only: take slick-logger-2.0.0.zip
or .tar.gz and add include/ to your include path. The archive is
self-contained - alongside slick/logger.hpp it bundles the
slick/queue.h and slick/shm/ headers it includes, from
slick-queue and
slick-shm, so there is no
separate dependency to install. Their licences are in licenses/.
slick-log-collector-* contains the prebuilt standalone collector for
multi-process logging.
It is optional; you only need it to collect log entries from several
processes into one set of sinks.