# FileChannel

<a id="filechannel"></a>

# FileChannel

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

class FileChannel
```

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

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

Log channel that writes formatted messages to a file.

## List of all members

| Name | Kind | Owner |
|------|------|-------|
| [`FileChannel`](#filechannel-1) | `function` | Declared here |
| [`~FileChannel`](#filechannel-2) | `function` | Declared here |
| [`write`](#write-2) | `function` | Declared here |
| [`setPath`](#setpath) | `function` | Declared here |
| [`path`](#path) | `function` | Declared here |
| [`_fstream`](#_fstream) | `variable` | Declared here |
| [`_path`](#_path) | `variable` | Declared here |
| [`open`](#open) | `function` | Declared here |
| [`close`](#close-1) | `function` | 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 |
|--------|------|-------------|
|  | [`FileChannel`](#filechannel-1)  |  |
|  | [`~FileChannel`](#filechannel-2) `virtual` |  |
| `void` | [`write`](#write-2) `virtual` `override` | Formats and writes the log stream entry to the file. Opens the file on first write if not already open. |
| `void` | [`setPath`](#setpath)  | Sets the file path and reopens the file stream. |
| `std::string` | [`path`](#path) `const` | Returns the current log file path. |

---

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

### FileChannel

```cpp
FileChannel(std::string name, std::string path, Level level = Level::Debug, std::string timeFormat = "%H:%M:%S")
```

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

#### Parameters

| Parameter | Type | Description |
|-----------|------|-------------|
| `name` | `std::string` | Unique channel name. |
| `path` | `std::string` | Path to the output log file. Directories are created if needed. |
| `level` | [`Level`](https://auscaster.com/icey/docs/api-reference/base.md#level) | Minimum severity level; messages below this level are dropped. |
| `timeFormat` | `std::string` | strftime-compatible format string for timestamps. |

---

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

### ~FileChannel

`virtual`

```cpp
virtual ~FileChannel()
```

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

---

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

### write

`virtual` `override`

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

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

Formats and writes the log stream entry to the file. Opens the file on first write if not already open.

#### 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="setpath"></a>

### setPath

```cpp
void setPath(const std::string & path)
```

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

Sets the file path and reopens the file stream.

#### Parameters

| Parameter | Type | Description |
|-----------|------|-------------|
| `path` | `const std::string &` | Path to the new log file. |

---

<a id="path"></a>

### path

`const`

```cpp
std::string path() const
```

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

Returns the current log file path. 
#### Returns
Absolute or relative path to the log file.

## Protected Attributes

| Return | Name | Description |
|--------|------|-------------|
| `std::ofstream` | [`_fstream`](#_fstream)  |  |
| `std::string` | [`_path`](#_path)  |  |

---

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

### _fstream

```cpp
std::ofstream _fstream
```

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

---

<a id="_path"></a>

### _path

```cpp
std::string _path
```

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

## Protected Methods

| Return | Name | Description |
|--------|------|-------------|
| `void` | [`open`](#open) `virtual` |  |
| `void` | [`close`](#close-1) `virtual` |  |

---

<a id="open"></a>

### open

`virtual`

```cpp
virtual void open()
```

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

---

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

### close

`virtual`

```cpp
virtual void close()
```

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