# RotatingFileChannel

<a id="rotatingfilechannel"></a>

# RotatingFileChannel

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

class RotatingFileChannel
```

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

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

Log channel that writes to time-rotated log files.

## List of all members

| Name | Kind | Owner |
|------|------|-------|
| [`RotatingFileChannel`](#rotatingfilechannel-1) | `function` | Declared here |
| [`~RotatingFileChannel`](#rotatingfilechannel-2) | `function` | Declared here |
| [`write`](#write-15) | `function` | Declared here |
| [`rotate`](#rotate) | `function` | Declared here |
| [`dir`](#dir) | `function` | Declared here |
| [`filename`](#filename) | `function` | Declared here |
| [`rotationInterval`](#rotationinterval) | `function` | Declared here |
| [`setDir`](#setdir) | `function` | Declared here |
| [`setExtension`](#setextension) | `function` | Declared here |
| [`setRotationInterval`](#setrotationinterval) | `function` | Declared here |
| [`_fstream`](#_fstream-1) | `variable` | Declared here |
| [`_dir`](#_dir) | `variable` | Declared here |
| [`_filename`](#_filename-1) | `variable` | Declared here |
| [`_extension`](#_extension) | `variable` | Declared here |
| [`_rotationInterval`](#_rotationinterval) | `variable` | Declared here |
| [`_rotatedAt`](#_rotatedat) | `variable` | Declared here |
| [`LogChannel`](https://auscaster.com/icey/docs/api-reference/icy-LogChannel.md#logchannel-1) | `function` | Inherited from [`LogChannel`](https://auscaster.com/icey/docs/api-reference/icy-LogChannel.md#logchannel) |
| [`~LogChannel`](https://auscaster.com/icey/docs/api-reference/icy-LogChannel.md#logchannel-2) | `function` | Inherited from [`LogChannel`](https://auscaster.com/icey/docs/api-reference/icy-LogChannel.md#logchannel) |
| [`write`](https://auscaster.com/icey/docs/api-reference/icy-LogChannel.md#write-5) | `function` | Inherited from [`LogChannel`](https://auscaster.com/icey/docs/api-reference/icy-LogChannel.md#logchannel) |
| [`write`](https://auscaster.com/icey/docs/api-reference/icy-LogChannel.md#write-6) | `function` | Inherited from [`LogChannel`](https://auscaster.com/icey/docs/api-reference/icy-LogChannel.md#logchannel) |
| [`format`](https://auscaster.com/icey/docs/api-reference/icy-LogChannel.md#format-4) | `function` | Inherited from [`LogChannel`](https://auscaster.com/icey/docs/api-reference/icy-LogChannel.md#logchannel) |
| [`name`](https://auscaster.com/icey/docs/api-reference/icy-LogChannel.md#name-1) | `function` | Inherited from [`LogChannel`](https://auscaster.com/icey/docs/api-reference/icy-LogChannel.md#logchannel) |
| [`level`](https://auscaster.com/icey/docs/api-reference/icy-LogChannel.md#level-1) | `function` | Inherited from [`LogChannel`](https://auscaster.com/icey/docs/api-reference/icy-LogChannel.md#logchannel) |
| [`timeFormat`](https://auscaster.com/icey/docs/api-reference/icy-LogChannel.md#timeformat) | `function` | Inherited from [`LogChannel`](https://auscaster.com/icey/docs/api-reference/icy-LogChannel.md#logchannel) |
| [`setLevel`](https://auscaster.com/icey/docs/api-reference/icy-LogChannel.md#setlevel) | `function` | Inherited from [`LogChannel`](https://auscaster.com/icey/docs/api-reference/icy-LogChannel.md#logchannel) |
| [`setTimeFormat`](https://auscaster.com/icey/docs/api-reference/icy-LogChannel.md#settimeformat) | `function` | Inherited from [`LogChannel`](https://auscaster.com/icey/docs/api-reference/icy-LogChannel.md#logchannel) |
| [`setFilter`](https://auscaster.com/icey/docs/api-reference/icy-LogChannel.md#setfilter) | `function` | Inherited from [`LogChannel`](https://auscaster.com/icey/docs/api-reference/icy-LogChannel.md#logchannel) |
| [`_name`](https://auscaster.com/icey/docs/api-reference/icy-LogChannel.md#_name) | `variable` | Inherited from [`LogChannel`](https://auscaster.com/icey/docs/api-reference/icy-LogChannel.md#logchannel) |
| [`_level`](https://auscaster.com/icey/docs/api-reference/icy-LogChannel.md#_level) | `variable` | Inherited from [`LogChannel`](https://auscaster.com/icey/docs/api-reference/icy-LogChannel.md#logchannel) |
| [`_timeFormat`](https://auscaster.com/icey/docs/api-reference/icy-LogChannel.md#_timeformat) | `variable` | Inherited from [`LogChannel`](https://auscaster.com/icey/docs/api-reference/icy-LogChannel.md#logchannel) |
| [`_filter`](https://auscaster.com/icey/docs/api-reference/icy-LogChannel.md#_filter) | `variable` | Inherited from [`LogChannel`](https://auscaster.com/icey/docs/api-reference/icy-LogChannel.md#logchannel) |

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

| Kind | Name | Description |
|------|------|-------------|
| `function` | [`LogChannel`](https://auscaster.com/icey/docs/api-reference/icy-LogChannel.md#logchannel-1)  |  |
| `function` | [`~LogChannel`](https://auscaster.com/icey/docs/api-reference/icy-LogChannel.md#logchannel-2) `virtual` | Defaulted destructor. |
| `function` | [`write`](https://auscaster.com/icey/docs/api-reference/icy-LogChannel.md#write-5) `virtual` | Writes a log stream entry to this channel. |
| `function` | [`write`](https://auscaster.com/icey/docs/api-reference/icy-LogChannel.md#write-6) `virtual` | Writes a plain message to this channel. |
| `function` | [`format`](https://auscaster.com/icey/docs/api-reference/icy-LogChannel.md#format-4) `virtual` | Formats a log stream entry into the given output stream. |
| `function` | [`name`](https://auscaster.com/icey/docs/api-reference/icy-LogChannel.md#name-1) `const` `inline` | Returns the channel name. |
| `function` | [`level`](https://auscaster.com/icey/docs/api-reference/icy-LogChannel.md#level-1) `const` `inline` | Returns the minimum severity level. |
| `function` | [`timeFormat`](https://auscaster.com/icey/docs/api-reference/icy-LogChannel.md#timeformat) `const` `inline` | Returns the timestamp format string. |
| `function` | [`setLevel`](https://auscaster.com/icey/docs/api-reference/icy-LogChannel.md#setlevel) `inline` | Sets the minimum severity level. |
| `function` | [`setTimeFormat`](https://auscaster.com/icey/docs/api-reference/icy-LogChannel.md#settimeformat) `inline` | Sets the timestamp format string. |
| `function` | [`setFilter`](https://auscaster.com/icey/docs/api-reference/icy-LogChannel.md#setfilter) `inline` | Sets a realm filter; only messages whose realm matches are written. |
| `variable` | [`_name`](https://auscaster.com/icey/docs/api-reference/icy-LogChannel.md#_name)  |  |
| `variable` | [`_level`](https://auscaster.com/icey/docs/api-reference/icy-LogChannel.md#_level)  |  |
| `variable` | [`_timeFormat`](https://auscaster.com/icey/docs/api-reference/icy-LogChannel.md#_timeformat)  |  |
| `variable` | [`_filter`](https://auscaster.com/icey/docs/api-reference/icy-LogChannel.md#_filter)  |  |

## Public Methods

| Return | Name | Description |
|--------|------|-------------|
|  | [`RotatingFileChannel`](#rotatingfilechannel-1)  |  |
|  | [`~RotatingFileChannel`](#rotatingfilechannel-2) `virtual` |  |
| `void` | [`write`](#write-15) `virtual` `override` | Formats and writes the log stream entry to the current log file. Rotates the file if the rotation interval has elapsed. |
| `void` | [`rotate`](#rotate) `virtual` | Closes the current log file and opens a new one with a timestamped filename. |
| `std::string` | [`dir`](#dir) `const` `inline` | Returns the directory where log files are written. |
| `std::string` | [`filename`](#filename) `const` `inline` | Returns the filename of the currently open log file. |
| `int` | [`rotationInterval`](#rotationinterval) `const` `inline` | Returns the rotation interval in seconds. |
| `void` | [`setDir`](#setdir) `inline` | Sets the output directory for rotated log files. |
| `void` | [`setExtension`](#setextension) `inline` | Sets the file extension for rotated log files. |
| `void` | [`setRotationInterval`](#setrotationinterval) `inline` | Sets the rotation interval. |

---

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

### RotatingFileChannel

```cpp
RotatingFileChannel(std::string name, std::string dir, Level level = Level::Debug, std::string extension = "log", int rotationInterval = 12 *3600, std::string timeFormat = "%H:%M:%S")
```

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

#### Parameters

| Parameter | Type | Description |
|-----------|------|-------------|
| `name` | `std::string` | Unique channel name. |
| `dir` | `std::string` | Directory in which rotated log files are written. |
| `level` | [`Level`](https://auscaster.com/icey/docs/api-reference/base.md#level) | Minimum severity level; messages below this level are dropped. |
| `extension` | `std::string` | File extension for log files (without leading dot). |
| `rotationInterval` | `int` | Seconds between log rotations (default: 12 hours). |
| `timeFormat` | `std::string` | strftime-compatible format string for timestamps. |

---

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

### ~RotatingFileChannel

`virtual`

```cpp
virtual ~RotatingFileChannel()
```

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

---

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

### write

`virtual` `override`

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

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

Formats and writes the log stream entry to the current log file. Rotates the file if the rotation interval has elapsed.

#### Reimplements

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

#### Parameters

| Parameter | Type | Description |
|-----------|------|-------------|
| `stream` | const [`LogStream`](https://auscaster.com/icey/docs/api-reference/icy-LogStream.md#logstream) & | The log stream to write. |

---

<a id="rotate"></a>

### rotate

`virtual`

```cpp
virtual void rotate()
```

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

Closes the current log file and opens a new one with a timestamped filename.

---

<a id="dir"></a>

### dir

`const` `inline`

```cpp
inline std::string dir() const
```

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

Returns the directory where log files are written.

---

<a id="filename"></a>

### filename

`const` `inline`

```cpp
inline std::string filename() const
```

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

Returns the filename of the currently open log file.

---

<a id="rotationinterval"></a>

### rotationInterval

`const` `inline`

```cpp
inline int rotationInterval() const
```

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

Returns the rotation interval in seconds.

---

<a id="setdir"></a>

### setDir

`inline`

```cpp
inline void setDir(std::string dir)
```

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

Sets the output directory for rotated log files.

#### Parameters

| Parameter | Type | Description |
|-----------|------|-------------|
| `dir` | `std::string` | Target directory path. |

---

<a id="setextension"></a>

### setExtension

`inline`

```cpp
inline void setExtension(std::string ext)
```

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

Sets the file extension for rotated log files.

#### Parameters

| Parameter | Type | Description |
|-----------|------|-------------|
| `ext` | `std::string` | Extension without leading dot (e.g. "log"). |

---

<a id="setrotationinterval"></a>

### setRotationInterval

`inline`

```cpp
inline void setRotationInterval(int interval)
```

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

Sets the rotation interval.

#### Parameters

| Parameter | Type | Description |
|-----------|------|-------------|
| `interval` | `int` | Number of seconds between rotations. |

## Protected Attributes

| Return | Name | Description |
|--------|------|-------------|
| `std::unique_ptr< std::ofstream >` | [`_fstream`](#_fstream-1)  |  |
| `std::string` | [`_dir`](#_dir)  |  |
| `std::string` | [`_filename`](#_filename-1)  |  |
| `std::string` | [`_extension`](#_extension)  |  |
| `int` | [`_rotationInterval`](#_rotationinterval)  | The log rotation interval in seconds. |
| `time_t` | [`_rotatedAt`](#_rotatedat)  | The time the log was last rotated. |

---

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

### _fstream

```cpp
std::unique_ptr< std::ofstream > _fstream
```

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

---

<a id="_dir"></a>

### _dir

```cpp
std::string _dir
```

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

---

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

### _filename

```cpp
std::string _filename
```

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

---

<a id="_extension"></a>

### _extension

```cpp
std::string _extension
```

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

---

<a id="_rotationinterval"></a>

### _rotationInterval

```cpp
int _rotationInterval
```

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

The log rotation interval in seconds.

---

<a id="_rotatedat"></a>

### _rotatedAt

```cpp
time_t _rotatedAt
```

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

The time the log was last rotated.
