# Logger

<a id="logger"></a>

# Logger

```cpp
#include <icy/logger.h>

class Logger
```

[Defined in src/base/include/icy/logger.h:156](https://github.com/auscaster/icey/blob/main/src/base/include/icy/logger.h#L156)

[Logger](#logger) class.

## Friends

| Name | Description |
|------|-------------|
| [`Singleton< Logger >`](#singletonlogger)  |  |
| [`Thread`](#thread)  |  |

---

<a id="singletonlogger"></a>

### Singleton< Logger >

```cpp
friend class Singleton< Logger >
```

[Defined in src/base/include/icy/logger.h:228](https://github.com/auscaster/icey/blob/main/src/base/include/icy/logger.h#L228)

---

<a id="thread"></a>

### Thread

```cpp
friend class Thread
```

[Defined in src/base/include/icy/logger.h:233](https://github.com/auscaster/icey/blob/main/src/base/include/icy/logger.h#L233)

## Public Methods

| Return | Name | Description |
|--------|------|-------------|
|  | [`Logger`](#logger-1)  |  |
|  | [`~Logger`](#logger-2)  |  |
| `void` | [`add`](#add-3)  | Adds the given log channel. Takes ownership. |
| `void` | [`remove`](#remove-2)  | Removes the given log channel by name. |
| [`LogChannel`](https://auscaster.com/icey/docs/api-reference/icy-LogChannel.md#logchannel) * | [`get`](#get-6) `const` | Returns the specified log channel. Throws an exception if the channel doesn't exist. |
| `void` | [`setDefault`](#setdefault)  | Sets the default log to the specified log channel. |
| `void` | [`setWriter`](#setwriter)  | Sets the log writer instance. Takes ownership. |
| [`LogChannel`](https://auscaster.com/icey/docs/api-reference/icy-LogChannel.md#logchannel) * | [`getDefault`](#getdefault-1) `const` | Returns the default log channel, or the nullptr channel if no default channel has been set. |
| `void` | [`write`](#write-7)  | Writes the given message to the default log channel. The message will be copied. |
| `void` | [`write`](#write-8)  | Writes the given message to the default log channel. |

---

<a id="logger-1"></a>

### Logger

```cpp
Logger()
```

[Defined in src/base/include/icy/logger.h:159](https://github.com/auscaster/icey/blob/main/src/base/include/icy/logger.h#L159)

---

<a id="logger-2"></a>

### ~Logger

```cpp
~Logger()
```

[Defined in src/base/include/icy/logger.h:160](https://github.com/auscaster/icey/blob/main/src/base/include/icy/logger.h#L160)

---

<a id="add-3"></a>

### add

```cpp
void add(std::unique_ptr< LogChannel > channel)
```

[Defined in src/base/include/icy/logger.h:173](https://github.com/auscaster/icey/blob/main/src/base/include/icy/logger.h#L173)

Adds the given log channel. Takes ownership.

---

<a id="remove-2"></a>

### remove

```cpp
void remove(std::string_view name)
```

[Defined in src/base/include/icy/logger.h:176](https://github.com/auscaster/icey/blob/main/src/base/include/icy/logger.h#L176)

Removes the given log channel by name.

---

<a id="get-6"></a>

### get

`const`

```cpp
LogChannel * get(std::string_view name, bool whiny = true) const
```

[Defined in src/base/include/icy/logger.h:180](https://github.com/auscaster/icey/blob/main/src/base/include/icy/logger.h#L180)

Returns the specified log channel. Throws an exception if the channel doesn't exist.

---

<a id="setdefault"></a>

### setDefault

```cpp
void setDefault(std::string_view name)
```

[Defined in src/base/include/icy/logger.h:183](https://github.com/auscaster/icey/blob/main/src/base/include/icy/logger.h#L183)

Sets the default log to the specified log channel.

---

<a id="setwriter"></a>

### setWriter

```cpp
void setWriter(std::unique_ptr< LogWriter > writer)
```

[Defined in src/base/include/icy/logger.h:186](https://github.com/auscaster/icey/blob/main/src/base/include/icy/logger.h#L186)

Sets the log writer instance. Takes ownership.

---

<a id="getdefault-1"></a>

### getDefault

`const`

```cpp
LogChannel * getDefault() const
```

[Defined in src/base/include/icy/logger.h:190](https://github.com/auscaster/icey/blob/main/src/base/include/icy/logger.h#L190)

Returns the default log channel, or the nullptr channel if no default channel has been set.

---

<a id="write-7"></a>

### write

```cpp
void write(const LogStream & stream)
```

[Defined in src/base/include/icy/logger.h:194](https://github.com/auscaster/icey/blob/main/src/base/include/icy/logger.h#L194)

Writes the given message to the default log channel. The message will be copied.

---

<a id="write-8"></a>

### write

```cpp
void write(std::unique_ptr< LogStream > stream)
```

[Defined in src/base/include/icy/logger.h:197](https://github.com/auscaster/icey/blob/main/src/base/include/icy/logger.h#L197)

Writes the given message to the default log channel.

## Public Static Methods

| Return | Name | Description |
|--------|------|-------------|
| [`Logger`](#logger) & | [`instance`](#instance-2) `static` | Returns the default logger singleton. [Logger](#logger) instances may be created separately as needed. |
| `void` | [`setInstance`](#setinstance) `static` | Sets the default logger singleton instance. |
| `void` | [`destroy`](#destroy) `static` | Destroys the default logger singleton instance. |
| `bool` | [`levelEnabled`](#levelenabled) `static` `inline` `noexcept` | Returns true if a message at the given level could be accepted by any existing channel. Cheap (single relaxed atomic load) so the logging macros can skip argument formatting entirely when the level is filtered out. Conservative: never filters a deliverable message, but raising a channel's level does not raise the filter back. |
| `void` | [`lowerLevelFilter`](#lowerlevelfilter) `static` `inline` `noexcept` | Lowers the global level filter so messages at `level` and above pass [`levelEnabled()`](#levelenabled). Called by [`LogChannel`](https://auscaster.com/icey/docs/api-reference/icy-LogChannel.md#logchannel) on construction and `setLevel()`. |

---

<a id="instance-2"></a>

### instance

`static`

```cpp
static Logger & instance()
```

[Defined in src/base/include/icy/logger.h:164](https://github.com/auscaster/icey/blob/main/src/base/include/icy/logger.h#L164)

Returns the default logger singleton. [Logger](#logger) instances may be created separately as needed.

---

<a id="setinstance"></a>

### setInstance

`static`

```cpp
static void setInstance(Logger * logger, bool freeExisting = true)
```

[Defined in src/base/include/icy/logger.h:167](https://github.com/auscaster/icey/blob/main/src/base/include/icy/logger.h#L167)

Sets the default logger singleton instance.

---

<a id="destroy"></a>

### destroy

`static`

```cpp
static void destroy()
```

[Defined in src/base/include/icy/logger.h:170](https://github.com/auscaster/icey/blob/main/src/base/include/icy/logger.h#L170)

Destroys the default logger singleton instance.

---

<a id="levelenabled"></a>

### levelEnabled

`static` `inline` `noexcept`

```cpp
static inline bool levelEnabled(Level level) noexcept
```

[Defined in src/base/include/icy/logger.h:204](https://github.com/auscaster/icey/blob/main/src/base/include/icy/logger.h#L204)

Returns true if a message at the given level could be accepted by any existing channel. Cheap (single relaxed atomic load) so the logging macros can skip argument formatting entirely when the level is filtered out. Conservative: never filters a deliverable message, but raising a channel's level does not raise the filter back.

---

<a id="lowerlevelfilter"></a>

### lowerLevelFilter

`static` `inline` `noexcept`

```cpp
static inline void lowerLevelFilter(Level level) noexcept
```

[Defined in src/base/include/icy/logger.h:213](https://github.com/auscaster/icey/blob/main/src/base/include/icy/logger.h#L213)

Lowers the global level filter so messages at `level` and above pass [`levelEnabled()`](#levelenabled). Called by [`LogChannel`](https://auscaster.com/icey/docs/api-reference/icy-LogChannel.md#logchannel) on construction and `setLevel()`.

## Protected Attributes

| Return | Name | Description |
|--------|------|-------------|
| `std::mutex` | [`_mutex`](#_mutex-2)  |  |
| `LogChannelMap` | [`_channels`](#_channels)  |  |
| [`LogChannel`](https://auscaster.com/icey/docs/api-reference/icy-LogChannel.md#logchannel) * | [`_defaultChannel`](#_defaultchannel)  |  |
| std::unique_ptr< [`LogWriter`](https://auscaster.com/icey/docs/api-reference/icy-LogWriter.md#logwriter) > | [`_writer`](#_writer)  |  |

---

<a id="_mutex-2"></a>

### _mutex

```cpp
std::mutex _mutex
```

[Defined in src/base/include/icy/logger.h:235](https://github.com/auscaster/icey/blob/main/src/base/include/icy/logger.h#L235)

---

<a id="_channels"></a>

### _channels

```cpp
LogChannelMap _channels
```

Type: `LogChannelMap`

[Defined in src/base/include/icy/logger.h:236](https://github.com/auscaster/icey/blob/main/src/base/include/icy/logger.h#L236)

---

<a id="_defaultchannel"></a>

### _defaultChannel

```cpp
LogChannel * _defaultChannel
```

Type: [`LogChannel`](https://auscaster.com/icey/docs/api-reference/icy-LogChannel.md#logchannel) *

[Defined in src/base/include/icy/logger.h:237](https://github.com/auscaster/icey/blob/main/src/base/include/icy/logger.h#L237)

---

<a id="_writer"></a>

### _writer

```cpp
std::unique_ptr< LogWriter > _writer
```

Type: std::unique_ptr< [`LogWriter`](https://auscaster.com/icey/docs/api-reference/icy-LogWriter.md#logwriter) >

[Defined in src/base/include/icy/logger.h:238](https://github.com/auscaster/icey/blob/main/src/base/include/icy/logger.h#L238)

## Protected Methods

| Return | Name | Description |
|--------|------|-------------|
|  | [`Logger`](#logger-3)  | NonCopyable and NonMovable. |
| [`Logger`](#logger) & | [`operator=`](#operator-59)  | Deleted assignment operator. |
|  | [`Logger`](#logger-4)  | Deleted constructor. |
| [`Logger`](#logger) & | [`operator=`](#operator-60)  | Deleted assignment operator. |

---

<a id="logger-3"></a>

### Logger

```cpp
Logger(const Logger &) = delete
```

[Defined in src/base/include/icy/logger.h:225](https://github.com/auscaster/icey/blob/main/src/base/include/icy/logger.h#L225)

NonCopyable and NonMovable.

---

<a id="operator-59"></a>

### operator=

```cpp
Logger & operator=(const Logger &) = delete
```

[Defined in src/base/include/icy/logger.h:226](https://github.com/auscaster/icey/blob/main/src/base/include/icy/logger.h#L226)

Deleted assignment operator.

---

<a id="logger-4"></a>

### Logger

```cpp
Logger(Logger &&) = delete
```

[Defined in src/base/include/icy/logger.h:227](https://github.com/auscaster/icey/blob/main/src/base/include/icy/logger.h#L227)

Deleted constructor.

---

<a id="operator-60"></a>

### operator=

```cpp
Logger & operator=(Logger &&) = delete
```

[Defined in src/base/include/icy/logger.h:228](https://github.com/auscaster/icey/blob/main/src/base/include/icy/logger.h#L228)

Deleted assignment operator.
