LoggerBuilder
Include fastly/log.h to use this class.
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
fastly::log::LoggerBuilder::LoggerBuilder()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.
Methods
Overload 1 of 2
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().
Parameters
- endpoint: Endpoint
Returns
123456789101112fastly::log::LoggerBuilder() .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");fastly::log::warn_to( "other_endpoint", "This will go to other_endpoint, though");Overload 2 of 2
LoggerBuilder fastly::log::LoggerBuilder::default_endpoint(std::string_view endpoint) &&Parameters
- endpoint: std::string_view
Returns
Overload 1 of 2
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
Parameters
Returns
123456789101112fastly::log::LoggerBuilder() .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");fastly::log::error_to( "other_endpoint", "This will go to other_endpoint, though");Overload 2 of 2
LoggerBuilder fastly::log::LoggerBuilder::default_level_endpoint(std::string_view endpoint, LogLevel level) &&Parameters
- endpoint: std::string_view
- level: LogLevel
Returns
echo_stderr
View sourceLoggerBuilder 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.
Parameters
- enabled: bool
Returns
echo_stdout
View sourceLoggerBuilder 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.
Parameters
- enabled: bool
Returns
Overload 1 of 2
Register an endpoint.
Parameters
- endpoint: Endpoint
Returns
fastly::log::LoggerBuilder() .max_level(log::LogLevelFilter::Trace) .endpoint("my_endpoint") .init();fastly::log::info_to("my_endpoint", "Hello");Overload 2 of 2
LoggerBuilder fastly::log::LoggerBuilder::endpoint(std::string_view endpoint) &&Parameters
- endpoint: std::string_view
Returns
Overload 1 of 2
LoggerBuilder fastly::log::LoggerBuilder::endpoint_level(Endpoint endpoint, LogLevelFilter level) &&Register an endpoint and set the maximum logging level for its messages.
Parameters
- endpoint: Endpoint
- level: LogLevelFilter
Returns
123456789101112fastly::log::LoggerBuilder() .max_level(fastly::log::LogLevelFilter::Trace) .endpoint_level("debug_endpoint", fastly::log::LogLevelFilter::Debug) .init();fastly::log::info_to( "debug_endpoint", "This will be written to debug_endpoint...");fastly::log::trace_to( "debug_endpoint", "...but this won't be...");Overload 2 of 2
LoggerBuilder fastly::log::LoggerBuilder::endpoint_level(std::string_view endpoint, LogLevelFilter level) &&Parameters
- endpoint: std::string_view
- level: LogLevelFilter
Returns
init
View sourcevoid 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.
Returns
fastly::log::LoggerBuilder() .default_endpoint("my_endpoint") .init();fastly::log::info("Hello");max_level
View sourceSet 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.
Parameters
- level: LogLevelFilter
Returns
123456789fastly::log::LoggerBuilder() .max_level(fastly::log::LogLevelFilter::Warn) .endpoint_level("my_endpoint", fastly::log::LogLevelFilter::Info) .init();fastly::log::warn_to( "my_endpoint", "This will be written to my_endpoint...");fastly::log::info_to("my_endpoint", "...but this won't");