---
title: log
summary: Logger implementation for Fastly Compute.
url: https://www.fastly.com/documentation/reference/compute/sdks/cpp/fastly/log/
---

**Kind:** Module  
**Package:** compute-sdk-cpp 0.7.0  
**Path:** `fastly::log`

Logger implementation for Fastly Compute.

With this logger configured, the various log statements, like [`fastly::log::error()`](https://www.fastly.com/documentation/reference/compute/sdks/cpp/fastly/log/fn.error/), [`fastly::log::debug()`](https://www.fastly.com/documentation/reference/compute/sdks/cpp/fastly/log/fn.debug/), etc will send log messages to your chosen [Real-Time Log Streaming](https://docs.fastly.com/en/guides/about-fastlys-realtime-log-streaming-features) endpoints. You should initialize the logger as soon as your program starts. Logging statements will not do anything before initialization.

See the [Fastly documentation](https://docs.fastly.com/en/guides/integrations#_logging-endpoints) 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()`](https://www.fastly.com/documentation/reference/compute/sdks/cpp/fastly/log/fn.init_simple/):

#### Advanced configuration

For more precise control, including multiple endpoints and default endpoints for different logging levels, use the [`LoggerBuilder`](https://www.fastly.com/documentation/reference/compute/sdks/cpp/fastly/log/class.LoggerBuilder/) interface. The first example is equivalent to:

The [`LoggerBuilder::max_level()`](https://www.fastly.com/documentation/reference/compute/sdks/cpp/fastly/log/class.LoggerBuilder/#method-max_level) option sets the most verbose level of logging that will be emitted. Logging statements above that level, like [`info()`](https://www.fastly.com/documentation/reference/compute/sdks/cpp/fastly/log/fn.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()`](https://www.fastly.com/documentation/reference/compute/sdks/cpp/fastly/log/class.LoggerBuilder/#method-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](https://www.fastly.com/blog/introducing-compute-edge-log-tailing-for-better-observability-and-easier-debugging) 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()`](https://www.fastly.com/documentation/reference/compute/sdks/cpp/fastly/log/class.LoggerBuilder/#method-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()`](https://www.fastly.com/documentation/reference/compute/sdks/cpp/fastly/log/class.LoggerBuilder/#method-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()`](https://www.fastly.com/documentation/reference/compute/sdks/cpp/fastly/log/fn.init_simple/)
- [`LoggerBuilder::endpoint()`](https://www.fastly.com/documentation/reference/compute/sdks/cpp/fastly/log/class.LoggerBuilder/#method-endpoint)
- [`LoggerBuilder::endpoint_level()`](https://www.fastly.com/documentation/reference/compute/sdks/cpp/fastly/log/class.LoggerBuilder/#method-endpoint_level)
- [`LoggerBuilder::default_endpoint()`](https://www.fastly.com/documentation/reference/compute/sdks/cpp/fastly/log/class.LoggerBuilder/#method-default_endpoint)
- [`LoggerBuilder::default_level_endpoint()`](https://www.fastly.com/documentation/reference/compute/sdks/cpp/fastly/log/class.LoggerBuilder/#method-default_level_endpoint)

You can pass the endpoint name as an `std::string_view`-able, or an explicit [`fastly::log::Endpoint`](https://www.fastly.com/documentation/reference/compute/sdks/cpp/fastly/log/class.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

| Name | Summary |
| --- | --- |
| [Endpoint](https://www.fastly.com/documentation/reference/compute/sdks/cpp/fastly/log/class.Endpoint/) | A Fastly logging endpoint. |
| [LoggerBuilder](https://www.fastly.com/documentation/reference/compute/sdks/cpp/fastly/log/class.LoggerBuilder/) | A builder class for configuring endpoints in detail. |

## Type aliases

| Name | Summary |
| --- | --- |
| [LogLevel](https://www.fastly.com/documentation/reference/compute/sdks/cpp/fastly/log/type.LogLevel/) |  |
| [LogLevelFilter](https://www.fastly.com/documentation/reference/compute/sdks/cpp/fastly/log/type.LogLevelFilter/) |  |

## Functions

| Name | Summary |
| --- | --- |
| [debug](https://www.fastly.com/documentation/reference/compute/sdks/cpp/fastly/log/fn.debug/) | Send a Debug-level message to the configured default endpoint. Supports C++20 format strings. |
| [debug_to](https://www.fastly.com/documentation/reference/compute/sdks/cpp/fastly/log/fn.debug_to/) | Send a Debug-level message to a specified configured endpoint. Supports C++20 format strings. |
| [error](https://www.fastly.com/documentation/reference/compute/sdks/cpp/fastly/log/fn.error/) | Send an Error-level message to the configured default endpoint. Supports C++20 format strings. |
| [error_to](https://www.fastly.com/documentation/reference/compute/sdks/cpp/fastly/log/fn.error_to/) | Send an Error-level message to a specified configured endpoint. Supports C++20 format strings. |
| [info](https://www.fastly.com/documentation/reference/compute/sdks/cpp/fastly/log/fn.info/) | Send an Info-level message to the configured default endpoint. Supports C++20 format strings. |
| [info_to](https://www.fastly.com/documentation/reference/compute/sdks/cpp/fastly/log/fn.info_to/) | Send an Info-level message to a specified configured endpoint. Supports C++20 format strings. |
| [init_simple](https://www.fastly.com/documentation/reference/compute/sdks/cpp/fastly/log/fn.init_simple/) | Initialize logging with a single endpoint filtered by log level. |
| [max_level](https://www.fastly.com/documentation/reference/compute/sdks/cpp/fastly/log/fn.max_level/) | Returns the current maximum log level. |
| [set_max_level](https://www.fastly.com/documentation/reference/compute/sdks/cpp/fastly/log/fn.set_max_level/) | Set the global maximum log level. |
| [trace](https://www.fastly.com/documentation/reference/compute/sdks/cpp/fastly/log/fn.trace/) | Send a Trace-level message to the configured default endpoint. Supports C++20 format strings. |
| [trace_to](https://www.fastly.com/documentation/reference/compute/sdks/cpp/fastly/log/fn.trace_to/) | Send a Trace-level message to a specified configured endpoint. Supports C++20 format strings. |
| [warn](https://www.fastly.com/documentation/reference/compute/sdks/cpp/fastly/log/fn.warn/) | Send a Warn-level message to the configured default endpoint. Supports C++20 format strings. |
| [warn_to](https://www.fastly.com/documentation/reference/compute/sdks/cpp/fastly/log/fn.warn_to/) | Send a Warn-level message to a specified configured endpoint. Supports C++20 format strings. |
