Poco

class FastLogger

Library: Foundation
Package: Logging
Header: Poco/FastLogger.h

Description

FastLogger is a high-performance drop-in replacement for Poco::Logger that uses the Quill logging library internally.

FastLogger provides the same API as Logger but achieves much lower latency (~9ns vs ~100ns) by using asynchronous logging with lock-free queues and a dedicated backend thread for I/O.

Key differences from Logger:

  • Logging is asynchronous - messages are queued and processed by a background thread, providing very low latency for the caller.
  • Formatting and output are handled by Quill's sinks internally, though setChannel() maps Poco channels to Quill sinks.
  • Thread-safe by design without mutex locks in the hot path.

FastLogger instances are organized hierarchically by name, similar to Logger. The name uses dot-separated components (e.g., "HTTP.Server.Request").

Usage is identical to Logger:

FastLogger& logger = FastLogger::get("MyApp.Component");
logger.information("Processing request");
logger.error("Failed to connect: %s", errorMsg);

Configuration via LoggingConfigurator is supported using the "fastloggers" section instead of "loggers".

Inheritance

Direct Base Classes: Channel

All Base Classes: Channel, Configurable, RefCountedObject

Member Summary

Member Functions: add, addFileSink, create, critical, debug, destroy, dump, ensureBackendStarted, error, fatal, find, flush, format, formatDump, formatImpl, get, getChannel, getLevel, getProperty, has, information, is, log, logImpl, name, names, notice, parent, parseLevel, root, setBackendOption, setChannel, setLevel, setPattern, setProperty, shutdown, startBackend, trace, unsafeGet, warning

Inherited Functions: close, duplicate, getProperty, log, open, referenceCount, release, setProperty

Types Aliases

LoggerMap protected

using LoggerMap = std::map < std::string, Ptr >;

Priority

using Priority = Message::Priority;

Ptr

using Ptr = AutoPtr < FastLogger >;

Constructors

FastLogger protected

FastLogger(
    const std::string & name,
    int level
);

Destructor

~FastLogger protected virtual

~FastLogger() override;

Member Functions

addFileSink static

static void addFileSink(
    const std::string & filename
);

Adds a file sink for log output.

create static

static FastLogger & create(
    const std::string & name,
    int level = Priority::PRIO_INFORMATION
);

Creates and returns a reference to a FastLogger with the given name and log level.

create static

static FastLogger & create(
    const std::string & name,
    Channel::Ptr pChannel,
    int level = Priority::PRIO_INFORMATION
);

Creates and returns a reference to a FastLogger with the given name, Channel and log level. The Channel is accepted for API compatibility but ignored (Quill handles output internally).

critical inline

void critical(
    const std::string & msg
);

Logs a critical message.

critical

void critical(
    const std::string & msg,
    const char * file,
    LineNumber line
);

Logs a critical message with source location.

critical inline

template < typename T, typename ... Args > void critical(
    const std::string & fmt,
    T arg1,
    Args && ... args
);

critical

bool critical() const;

Returns true if the log level is at least PRIO_CRITICAL.

debug inline

void debug(
    const std::string & msg
);

Logs a debug message.

debug

void debug(
    const std::string & msg,
    const char * file,
    LineNumber line
);

Logs a debug message with source location.

debug inline

template < typename T, typename ... Args > void debug(
    const std::string & fmt,
    T arg1,
    Args && ... args
);

debug

bool debug() const;

Returns true if the log level is at least PRIO_DEBUG.

destroy static

static void destroy(
    const std::string & name
);

Destroys the logger with the specified name.

dump

void dump(
    const std::string & msg,
    const void * buffer,
    std::size_t length,
    Priority prio = Priority::PRIO_DEBUG
);

Logs the given message, followed by the data in buffer.

The data in buffer is written in canonical hex+ASCII form: Offset (4 bytes) in hexadecimal, followed by sixteen space-separated, two column, hexadecimal bytes, followed by the same sixteen bytes as ASCII characters. For bytes outside the range 32 .. 127, a dot is printed.

error inline

void error(
    const std::string & msg
);

Logs an error message.

error

void error(
    const std::string & msg,
    const char * file,
    LineNumber line
);

Logs an error message with source location.

error inline

template < typename T, typename ... Args > void error(
    const std::string & fmt,
    T arg1,
    Args && ... args
);

error

bool error() const;

Returns true if the log level is at least PRIO_ERROR.

fatal inline

void fatal(
    const std::string & msg
);

Logs a fatal message.

fatal

void fatal(
    const std::string & msg,
    const char * file,
    LineNumber line
);

Logs a fatal message with source location.

fatal inline

template < typename T, typename ... Args > void fatal(
    const std::string & fmt,
    T arg1,
    Args && ... args
);

fatal

bool fatal() const;

Returns true if the log level is at least PRIO_FATAL.

flush

void flush();

Blocks the calling thread until all log messages from this logger are flushed to the sinks. Use this when you need to ensure all pending messages are written before proceeding.

Note: This should not be called from a static destructor.

format static

static std::string format(
    const std::string & fmt,
    const std::string & arg
);

Replaces all occurrences of $0 in fmt with the string given in arg and returns the result. To include a dollar sign in the result string, specify two dollar signs ($$) in the format string.

format static

static std::string format(
    const std::string & fmt,
    const std::string & arg0,
    const std::string & arg1
);

Replaces all occurrences of $<n> in fmt with the string given in arg<n> and returns the result.

format static

static std::string format(
    const std::string & fmt,
    const std::string & arg0,
    const std::string & arg1,
    const std::string & arg2
);

Replaces all occurrences of $<n> in fmt with the string given in arg<n> and returns the result.

format static

static std::string format(
    const std::string & fmt,
    const std::string & arg0,
    const std::string & arg1,
    const std::string & arg2,
    const std::string & arg3
);

Replaces all occurrences of $<n> in fmt with the string given in arg<n> and returns the result.

formatDump static

static void formatDump(
    std::string & message,
    const void * buffer,
    std::size_t length
);

Creates a hex-dump of the given buffer and appends it to the given message string.

get static

static FastLogger & get(
    const std::string & name
);

Returns a reference to the FastLogger with the given name. If the logger does not exist, it is created based on its parent.

getChannel

Channel::Ptr getChannel() const;

Returns the Channel. For FastLogger this returns a null pointer as Quill handles output internally, but provided for API compatibility.

getLevel inline

int getLevel() const;

Returns the logger's log level.

getProperty virtual

std::string getProperty(
    const std::string & name
) const override;

Returns the value of the property with the given name.

Supported properties:

  • level: Returns the log level as a string

has static

static Ptr has(
    const std::string & name
);

Returns a pointer to the FastLogger if it exists, null otherwise.

information inline

void information(
    const std::string & msg
);

Logs an informational message.

information

void information(
    const std::string & msg,
    const char * file,
    LineNumber line
);

Logs an informational message with source location.

information inline

template < typename T, typename ... Args > void information(
    const std::string & fmt,
    T arg1,
    Args && ... args
);

information

bool information() const;

Returns true if the log level is at least PRIO_INFORMATION.

is inline

bool is(
    int level
) const;

Returns true if at least the given log level is set.

log virtual

void log(
    const Message & msg
) override;

Logs the given message if its priority is greater than or equal to the logger's log level.

log

void log(
    const Exception & exc
);

Logs the given exception with priority PRIO_ERROR.

log

void log(
    const Exception & exc,
    const char * file,
    LineNumber line
);

Logs the given exception with priority PRIO_ERROR.

File must be a static string, such as the value of the __FILE__ macro.

name inline

const std::string & name() const;

Returns the name of the logger.

names static

static void names(
    std::vector < std::string > & names
);

Fills the vector with names of all defined loggers.

notice inline

void notice(
    const std::string & msg
);

Logs a notice message.

notice

void notice(
    const std::string & msg,
    const char * file,
    LineNumber line
);

Logs a notice message with source location.

notice inline

template < typename T, typename ... Args > void notice(
    const std::string & fmt,
    T arg1,
    Args && ... args
);

notice

bool notice() const;

Returns true if the log level is at least PRIO_NOTICE.

parseLevel static

static int parseLevel(
    const std::string & level
);

Parses a symbolic log level string and returns the numeric level.

root static

static FastLogger & root();

Returns a reference to the root logger.

setBackendOption static

static void setBackendOption(
    const std::string & name,
    const std::string & value
);

Sets a Quill backend option before the backend is started. Must be called before any logging occurs.

Supported options:

  • threadName: Name of the backend thread (default: "QuillBackend")
  • sleepDuration: Backend sleep duration in microseconds (default: 100)
  • enableYieldWhenIdle: Enable yielding when idle (default: false)
  • enableCpuAffinity: Enable CPU affinity for backend thread (default: false)
  • cpuAffinity: Pin backend thread to specific CPU core (default: last core if enableCpuAffinity=true)
  • transitEventBufferInitialCapacity: Initial transit buffer size (default: 256)
  • transitEventsSoftLimit: Soft limit for transit events (default: 8192)
  • transitEventsHardLimit: Hard limit for transit events (default: 65536)
  • logTimestampOrderingGracePeriod: Grace period in microseconds (default: 5)
  • sinkMinFlushInterval: Min flush interval in milliseconds (default: 200)
  • waitForQueuesToEmptyBeforeExit: Wait on exit (default: true)

setChannel

void setChannel(
    Channel::Ptr pChannel
);

Sets the Channel. For FastLogger this is a no-op as Quill handles output internally, but provided for API compatibility.

setChannel static

static void setChannel(
    const std::string & name,
    Channel::Ptr pChannel
);

Sets the Channel on all loggers that are descendants of the logger with the given name. For FastLogger this is a no-op as Quill handles output internally, but provided for API compatibility.

setLevel

void setLevel(
    int level
);

Sets the logger's log level.

See Message::Priority for valid log levels. Setting the log level to zero turns off logging for that logger.

setLevel

void setLevel(
    const std::string & level
);

Sets the logger's log level using a symbolic value.

Valid values are:

  • none (turns off logging)
  • fatal
  • critical
  • error
  • warning
  • notice
  • information
  • debug
  • trace

setLevel static

static void setLevel(
    const std::string & name,
    int level
);

Sets the log level on all loggers that are descendants of the logger with the given name.

setPattern static

static void setPattern(
    const std::string & pattern
);

Sets the log output pattern for the console sink. Uses Quill pattern syntax.

setProperty virtual

void setProperty(
    const std::string & name,
    const std::string & value
) override;

Sets a configuration property.

Supported properties:

setProperty static

static void setProperty(
    const std::string & loggerName,
    const std::string & propertyName,
    const std::string & value
);

Sets a property on all loggers that are descendants of the logger with the given name.

shutdown static

static void shutdown();

Shuts down the logging framework, stopping the backend thread and flushing all pending messages.

startBackend static

static void startBackend();

Starts the Quill backend thread. Called automatically on first use.

trace inline

void trace(
    const std::string & msg
);

Logs a trace message.

trace

void trace(
    const std::string & msg,
    const char * file,
    LineNumber line
);

Logs a trace message with source location.

trace inline

template < typename T, typename ... Args > void trace(
    const std::string & fmt,
    T arg1,
    Args && ... args
);

trace

bool trace() const;

Returns true if the log level is at least PRIO_TRACE.

unsafeGet static

static FastLogger & unsafeGet(
    const std::string & name
);

Returns a reference to the FastLogger with the given name. Non-thread-safe version for use during initialization.

warning inline

void warning(
    const std::string & msg
);

Logs a warning message.

warning

void warning(
    const std::string & msg,
    const char * file,
    LineNumber line
);

Logs a warning message with source location.

warning inline

template < typename T, typename ... Args > void warning(
    const std::string & fmt,
    T arg1,
    Args && ... args
);

warning

bool warning() const;

Returns true if the log level is at least PRIO_WARNING.

add protected static

static void add(
    Ptr pLogger
);

ensureBackendStarted protected static

static void ensureBackendStarted();

find protected static

static Ptr find(
    const std::string & name
);

formatImpl protected static

static std::string formatImpl(
    const std::string & fmt,
    int argc,
    std::string argv[]
);

logImpl protected

void logImpl(
    const std::string & text,
    Priority prio
);

logImpl protected

void logImpl(
    const std::string & text,
    Priority prio,
    const char * file,
    LineNumber line
);

parent protected static

static FastLogger & parent(
    const std::string & name
);

Variables

ROOT static

static const std::string ROOT;

The name of the root logger ("").