LoggerBuilder

Classin logcompute-sdk-cpp 0.7.0View source

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

default_endpoint

Overload 1 of 2

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

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

1
2
3
4
5
6
7
8
9
10
11
12
fastly::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) &&
View source

Parameters

endpoint: std::string_view

Returns

default_level_endpoint

Overload 1 of 2

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

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

endpoint: Endpoint
level: LogLevel

Returns

1
2
3
4
5
6
7
8
9
10
11
12
fastly::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) &&
View source

Parameters

endpoint: std::string_view
level: LogLevel

Returns

echo_stderr

View source
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.

Parameters

enabled: bool

Returns

echo_stdout

View source
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.

Parameters

enabled: bool

Returns

endpoint

Overload 1 of 2

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

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) &&
View source

Parameters

endpoint: std::string_view

Returns

endpoint_level

Overload 1 of 2

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

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

Parameters

endpoint: Endpoint
level: LogLevelFilter

Returns

1
2
3
4
5
6
7
8
9
10
11
12
fastly::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) &&
View source

Parameters

endpoint: std::string_view
level: LogLevelFilter

Returns

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.

Returns

void
fastly::log::LoggerBuilder()
.default_endpoint("my_endpoint")
.init();
fastly::log::info("Hello");

max_level

View source
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.

Parameters

level: LogLevelFilter

Returns

1
2
3
4
5
6
7
8
9
fastly::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");