---
title: LoggerBuilder
summary: A builder class for configuring endpoints in detail.
url: https://www.fastly.com/documentation/reference/compute/sdks/cpp/fastly/log/class.LoggerBuilder/
---

**Kind:** Class  
**Module:** [log](https://www.fastly.com/documentation/reference/compute/sdks/cpp/fastly/log/)  
**Package:** compute-sdk-cpp 0.7.0  
**Source:** https://github.com/fastly/compute-sdk-cpp/blob/ff911e47be2f319e83a9cde960d2c3c5db534280/include/fastly/log.h#L470

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

**Source:** https://github.com/fastly/compute-sdk-cpp/blob/ff911e47be2f319e83a9cde960d2c3c5db534280/include/fastly/log.h#L476

```cpp
fastly::log::LoggerBuilder::LoggerBuilder()
```

Create a new [`LoggerBuilder`](https://www.fastly.com/documentation/reference/compute/sdks/cpp/fastly/log/class.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_

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

**Source:** https://github.com/fastly/compute-sdk-cpp/blob/ff911e47be2f319e83a9cde960d2c3c5db534280/include/fastly/log.h#L533

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()`](https://www.fastly.com/documentation/reference/compute/sdks/cpp/fastly/log/class.LoggerBuilder/#method-default_level_endpoint).

**Parameters**

- `endpoint`: `Endpoint`

**Returns**

`LoggerBuilder`

```cpp
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_

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

**Source:** https://github.com/fastly/compute-sdk-cpp/blob/ff911e47be2f319e83a9cde960d2c3c5db534280/include/fastly/log.h#L534

**Parameters**

- `endpoint`: `std::string_view`

**Returns**

`LoggerBuilder`

### default_level_endpoint

_Overload 1 of 2_

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

**Source:** https://github.com/fastly/compute-sdk-cpp/blob/ff911e47be2f319e83a9cde960d2c3c5db534280/include/fastly/log.h#L564

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()`](https://www.fastly.com/documentation/reference/compute/sdks/cpp/fastly/log/class.LoggerBuilder/#method-default_endpoint).

**Note:** Unlike most/all other functions in this module, the level is actually a [`fastly::log::LogLevel`](https://www.fastly.com/documentation/reference/compute/sdks/cpp/fastly/log/type.LogLevel/), not a [`fastly::log::LogLevelFilter`](https://www.fastly.com/documentation/reference/compute/sdks/cpp/fastly/log/type.LogLevelFilter/), and refers to a *specific* level, not a range.

###### Example

**Parameters**

- `endpoint`: `Endpoint`
- `level`: `LogLevel`

**Returns**

`LoggerBuilder`

```cpp
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_

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

**Source:** https://github.com/fastly/compute-sdk-cpp/blob/ff911e47be2f319e83a9cde960d2c3c5db534280/include/fastly/log.h#L565

**Parameters**

- `endpoint`: `std::string_view`
- `level`: `LogLevel`

**Returns**

`LoggerBuilder`

### echo_stderr

**Source:** https://github.com/fastly/compute-sdk-cpp/blob/ff911e47be2f319e83a9cde960d2c3c5db534280/include/fastly/log.h#L609

```cpp
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](https://www.fastly.com/blog/introducing-compute-edge-log-tailing-for-better-observability-and-easier-debugging).

**Parameters**

- `enabled`: `bool`

**Returns**

`LoggerBuilder`

### echo_stdout

**Source:** https://github.com/fastly/compute-sdk-cpp/blob/ff911e47be2f319e83a9cde960d2c3c5db534280/include/fastly/log.h#L598

```cpp
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](https://www.fastly.com/blog/introducing-compute-edge-log-tailing-for-better-observability-and-easier-debugging).

**Parameters**

- `enabled`: `bool`

**Returns**

`LoggerBuilder`

### endpoint

_Overload 1 of 2_

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

**Source:** https://github.com/fastly/compute-sdk-cpp/blob/ff911e47be2f319e83a9cde960d2c3c5db534280/include/fastly/log.h#L487

Register an endpoint.

**Parameters**

- `endpoint`: `Endpoint`

**Returns**

`LoggerBuilder`

```cpp
fastly::log::LoggerBuilder()
    .max_level(log::LogLevelFilter::Trace)
    .endpoint("my_endpoint")
    .init();
fastly::log::info_to("my_endpoint", "Hello");
```

_Overload 2 of 2_

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

**Source:** https://github.com/fastly/compute-sdk-cpp/blob/ff911e47be2f319e83a9cde960d2c3c5db534280/include/fastly/log.h#L488

**Parameters**

- `endpoint`: `std::string_view`

**Returns**

`LoggerBuilder`

### endpoint_level

_Overload 1 of 2_

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

**Source:** https://github.com/fastly/compute-sdk-cpp/blob/ff911e47be2f319e83a9cde960d2c3c5db534280/include/fastly/log.h#L506

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

**Parameters**

- `endpoint`: `Endpoint`
- `level`: `LogLevelFilter`

**Returns**

`LoggerBuilder`

```cpp
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_

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

**Source:** https://github.com/fastly/compute-sdk-cpp/blob/ff911e47be2f319e83a9cde960d2c3c5db534280/include/fastly/log.h#L507

**Parameters**

- `endpoint`: `std::string_view`
- `level`: `LogLevelFilter`

**Returns**

`LoggerBuilder`

### init

**Source:** https://github.com/fastly/compute-sdk-cpp/blob/ff911e47be2f319e83a9cde960d2c3c5db534280/include/fastly/log.h#L623

```cpp
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`

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

### max_level

**Source:** https://github.com/fastly/compute-sdk-cpp/blob/ff911e47be2f319e83a9cde960d2c3c5db534280/include/fastly/log.h#L587

```cpp
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**

`LoggerBuilder`

```cpp
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");
```
