log
fastly::log
Logger implementation for Fastly Compute.
With this logger configured, the various log statements, like fastly::log::error(), fastly::log::debug(), etc will send log messages to your chosen Real-Time Log Streaming endpoints. You should initialize the logger as soon as your program starts. Logging statements will not do anything before initialization.
See the Fastly documentation for more information about configuring logging endpoints for your service.
Getting started
All you need to get started is your endpoint name and the level of log messages you want to emit. For example, if you have an endpoint called my_endpoint, and you only want to emit log messages at the LogLevel::Warn or LogLevel::Error level, you can use fastly::log::init_simple():
Advanced configuration
For more precise control, including multiple endpoints and default endpoints for different logging levels, use the LoggerBuilder interface. The first example is equivalent to:
The LoggerBuilder::max_level() option sets the most verbose level of logging that will be emitted. Logging statements above that level, like info() in the first example, will do nothing.
Note: The default level is LevelFilter::Off, which emits no logging at all. You'll want to change this for most configurations.
LoggerBuilder::default_endpoint() sets the endpoint used whenever a plain logging statement is called (the ones not suffixed with _to) to specify its endpoint. With the default endpoint set to my_endpoint, the logging statements in the first example are equivalent to:
Use with Compute Log Tailing
Compute Log Tailing is helpful for getting debugging output quickly from a Compute program under development by capturing output from stdout or stderr. To configure logging to output to stdout or stderr in addition to the specified log endpoint, enable echoing when building the logger:
Multiple endpoints
Setting an endpoint as the default will automatically register it for use with the logger, but you can register additional endpoints with LoggerBuilder::endpoint():
Per-endpoint logging levels
You can also set a per-endpoint logging level, though levels higher than max_level are always ignored:
Per-level default endpoints
In the previous examples, the same endpoint is set as the default for all logging levels. You can also specify default endpoints for individual levels using LoggerBuilder::default_level_endpoint(). The defaults are combined in order, so you can specify an overall default endpoint, and then as many level-specific endpoints as you need:
Registering endpoints
All endpoints used by your logging statements must be registered when the logger is created. The following functions automatically register an endpoint if it is not already registered.
init_simple()LoggerBuilder::endpoint()LoggerBuilder::endpoint_level()LoggerBuilder::default_endpoint()LoggerBuilder::default_level_endpoint()
You can pass the endpoint name as an std::string_view-able, or an explicit fastly::log::Endpoint value. The following examples are equivalent:
If a logging statement uses one of the _to-suffixed versions with "my_endpoint" but my_endpoint is not registered, the message will be logged to the default endpoint for that level, if one exists.
Classes
| Endpoint | A Fastly logging endpoint. |
| LoggerBuilder | A builder class for configuring endpoints in detail. |
Functions
| debug | Send a Debug-level message to the configured default endpoint. Supports C++20 format strings. |
| debug_to | Send a Debug-level message to a specified configured endpoint. Supports C++20 format strings. |
| error | Send an Error-level message to the configured default endpoint. Supports C++20 format strings. |
| error_to | Send an Error-level message to a specified configured endpoint. Supports C++20 format strings. |
| info | Send an Info-level message to the configured default endpoint. Supports C++20 format strings. |
| info_to | Send an Info-level message to a specified configured endpoint. Supports C++20 format strings. |
| init_simple | Initialize logging with a single endpoint filtered by log level. |
| max_level | Returns the current maximum log level. |
| set_max_level | Set the global maximum log level. |
| trace | Send a Trace-level message to the configured default endpoint. Supports C++20 format strings. |
| trace_to | Send a Trace-level message to a specified configured endpoint. Supports C++20 format strings. |
| warn | Send a Warn-level message to the configured default endpoint. Supports C++20 format strings. |
| warn_to | Send a Warn-level message to a specified configured endpoint. Supports C++20 format strings. |