Fastly Compute C++ SDK
Loading...
Searching...
No Matches
fastly::log::LoggerBuilder Class Reference

#include <log.h>

Public Member Functions

 LoggerBuilder ()
LoggerBuilder endpoint (Endpoint endpoint) &&
LoggerBuilder endpoint (std::string_view endpoint) &&
LoggerBuilder endpoint_level (Endpoint endpoint, LogLevelFilter level) &&
LoggerBuilder endpoint_level (std::string_view endpoint, LogLevelFilter level) &&
LoggerBuilder default_endpoint (Endpoint endpoint) &&
LoggerBuilder default_endpoint (std::string_view endpoint) &&
LoggerBuilder default_level_endpoint (Endpoint endpoint, LogLevel level) &&
LoggerBuilder default_level_endpoint (std::string_view endpoint, LogLevel level) &&
LoggerBuilder max_level (LogLevelFilter level) &&
LoggerBuilder echo_stdout (bool enabled) &&
LoggerBuilder echo_stderr (bool enabled) &&
void init ()

Detailed Description

A builder class for configuring endpoints in detail.

You can use this builder to register endpoints, set default endpoints, control the levels of logging messages emitted, and filter messages based on module name.

Constructor & Destructor Documentation

◆ LoggerBuilder()

fastly::log::LoggerBuilder::LoggerBuilder ( )
inline

Create a new LoggerBuilder.

By default, no endpoints are registered, the maximum log level is set to LogLevelFilter::Off, and no module name filtering is done.

Member Function Documentation

◆ default_endpoint() [1/2]

LoggerBuilder fastly::log::LoggerBuilder::default_endpoint ( Endpoint endpoint) &&

Set the default endpoint for all messages.

The default endpoint is used when the logging statement does not use the _to-suffixed logger statements.

This overrides any previous default endpoints, set either by this method or by LoggerBuilder::default_level_endpoint().

.max_level(fastly::log::LogLevelFilter::Info)
.default_level_endpoint("error_only", fastly::log::Level::Error)
.default_endpoint("my_endpoint")
.endpoint("other_endpoint")
.init();
fastly::log::info("This will be written to my_endpoint...");
fastly::log::error("...and this will too");
"other_endpoint",
"This will go to other_endpoint, though"
);
Definition log.h:470
LoggerBuilder default_level_endpoint(Endpoint endpoint, LogLevel level) &&
LoggerBuilder endpoint(Endpoint endpoint) &&
LoggerBuilder max_level(LogLevelFilter level) &&
LoggerBuilder default_endpoint(Endpoint endpoint) &&
void warn_to(std::string_view dest, std::format_string< Args... > fmt, Args &&...args)
Definition log.h:274
void error(std::format_string< Args... > fmt, Args &&...args)
Definition log.h:210
void info(std::format_string< Args... > fmt, Args &&...args)
Definition log.h:294

◆ default_endpoint() [2/2]

LoggerBuilder fastly::log::LoggerBuilder::default_endpoint ( std::string_view endpoint) &&

◆ default_level_endpoint() [1/2]

LoggerBuilder fastly::log::LoggerBuilder::default_level_endpoint ( Endpoint endpoint,
LogLevel level ) &&

Set the default endpoint for all messages of the given level.

The default endpoint is used when the logging statement does not use one of the _to-suffixed functions.

This overrides any previous default endpoints set for this level, either by this method or by LoggerBuilder::default_endpoint().

Note: Unlike most/all other functions in this module, the level is actually a fastly::log::LogLevel, not a fastly::log::LogLevelFilter, and refers to a specific level, not a range.

Example

.max_level(fastly::log::LogLevelFilter::Info)
.default_endpoint("my_endpoint")
.default_level_endpoint("error_only", fastly::log::Level::Error)
.endpoint("other_endpoint")
.init();
fastly::log::info("This will be written to my_endpoint...");
fastly::log::error("...but this will be written to error_only");
"other_endpoint",
"This will go to other_endpoint, though"
);
void error_to(std::string_view dest, std::format_string< Args... > fmt, Args &&...args)
Definition log.h:232

◆ default_level_endpoint() [2/2]

LoggerBuilder fastly::log::LoggerBuilder::default_level_endpoint ( std::string_view endpoint,
LogLevel level ) &&

◆ echo_stderr()

LoggerBuilder fastly::log::LoggerBuilder::echo_stderr ( bool enabled) &&

Set whether all log messages should be echoed to stderr (false by default).

If this is set to true, all logging statements will write the message to stderr in addition to the specified endpoint. This is particularly useful when debugging with Compute Log Tailing.

◆ echo_stdout()

LoggerBuilder fastly::log::LoggerBuilder::echo_stdout ( bool enabled) &&

Set whether all log messages should be echoed to stdout (false by default).

If this is set to true, all logging statements will write the message to stdout in addition to the specified endpoint. This is particularly useful when debugging with Compute Log Tailing.

◆ endpoint() [1/2]

LoggerBuilder fastly::log::LoggerBuilder::endpoint ( Endpoint endpoint) &&

Register an endpoint.

.max_level(log::LogLevelFilter::Trace)
.endpoint("my_endpoint")
.init();
fastly::log::info_to("my_endpoint", "Hello");
void info_to(std::string_view dest, std::format_string< Args... > fmt, Args &&...args)
Definition log.h:316

◆ endpoint() [2/2]

LoggerBuilder fastly::log::LoggerBuilder::endpoint ( std::string_view endpoint) &&

◆ endpoint_level() [1/2]

LoggerBuilder fastly::log::LoggerBuilder::endpoint_level ( Endpoint endpoint,
LogLevelFilter level ) &&

Register an endpoint and set the maximum logging level for its messages.

.max_level(fastly::log::LogLevelFilter::Trace)
.endpoint_level("debug_endpoint", fastly::log::LogLevelFilter::Debug)
.init();
"debug_endpoint",
"This will be written to debug_endpoint..."
);
"debug_endpoint",
"...but this won't be..."
);
LoggerBuilder endpoint_level(Endpoint endpoint, LogLevelFilter level) &&
void trace_to(std::string_view dest, std::format_string< Args... > fmt, Args &&...args)
Definition log.h:400

◆ endpoint_level() [2/2]

LoggerBuilder fastly::log::LoggerBuilder::endpoint_level ( std::string_view endpoint,
LogLevelFilter level ) &&

◆ init()

void fastly::log::LoggerBuilder::init ( )

Build the logger and initialize it as the global logger.

Panics

This may panic for various reasons if the logger fails to initialize.

◆ max_level()

LoggerBuilder fastly::log::LoggerBuilder::max_level ( LogLevelFilter level) &&

Set the maximum logging level for all messages.

No messages that exceed this level will be emitted, even if a higher level is set for a specific endpoint or module name.

Note: The default level is LogLevelFilter::Off, which emits no logging at all. You'll want to change this for most configurations.

.max_level(fastly::log::LogLevelFilter::Warn)
.endpoint_level("my_endpoint", fastly::log::LogLevelFilter::Info)
.init();
"my_endpoint",
"This will be written to my_endpoint..."
);
fastly::log::info_to("my_endpoint", "...but this won't");

The documentation for this class was generated from the following file: