# Logging - Platform

# Logging - Platform

This module includes the platform abstraction for the debug log service.

## Summary

| ### Enumerations ||
|---|---|
| `https://openthread.io/reference/group/plat-logging#group__plat-logging_1gaee25d56d067df60b93f75b2ff587668c{ https://openthread.io/reference/group/plat-logging#group__plat-logging_1ggaee25d56d067df60b93f75b2ff587668ca035d48996c365d85e4d45d9bf0e4a1e5 = 1, https://openthread.io/reference/group/plat-logging#group__plat-logging_1ggaee25d56d067df60b93f75b2ff587668ca11b4d682838585bfcd8de18b8da8489f = 2, https://openthread.io/reference/group/plat-logging#group__plat-logging_1ggaee25d56d067df60b93f75b2ff587668cad4e4277f13b0004154a4752c35e2492a = 3, https://openthread.io/reference/group/plat-logging#group__plat-logging_1ggaee25d56d067df60b93f75b2ff587668ca10fc429c24ff6bccd100182363c12a67 = 4, https://openthread.io/reference/group/plat-logging#group__plat-logging_1ggaee25d56d067df60b93f75b2ff587668cabdbd31167a6f5efb5e35426eb8fb4d1a = 5, https://openthread.io/reference/group/plat-logging#group__plat-logging_1ggaee25d56d067df60b93f75b2ff587668caf9943bb06231d25b972727d93b69cbbd = 6, https://openthread.io/reference/group/plat-logging#group__plat-logging_1ggaee25d56d067df60b93f75b2ff587668caf2d33cf901ed575704b4523a57b64907 = 7, https://openthread.io/reference/group/plat-logging#group__plat-logging_1ggaee25d56d067df60b93f75b2ff587668ca8486c90c340479177e175374687a2267 = 8, https://openthread.io/reference/group/plat-logging#group__plat-logging_1ggaee25d56d067df60b93f75b2ff587668ca96f0bc11bb2edcca16e9b64279b04fc4 = 9, https://openthread.io/reference/group/plat-logging#group__plat-logging_1ggaee25d56d067df60b93f75b2ff587668cadc9701e21d9c4f155d078ec89e5f679d = 10, https://openthread.io/reference/group/plat-logging#group__plat-logging_1ggaee25d56d067df60b93f75b2ff587668ca206f1070d267f7e59ebfd3975fe68a05 = 11, https://openthread.io/reference/group/plat-logging#group__plat-logging_1ggaee25d56d067df60b93f75b2ff587668caebaf21c12a0d460c5a607c2770e3341d = 12, https://openthread.io/reference/group/plat-logging#group__plat-logging_1ggaee25d56d067df60b93f75b2ff587668cac5c150b337284ff78ac0733fa90fe9b0 = 13, https://openthread.io/reference/group/plat-logging#group__plat-logging_1ggaee25d56d067df60b93f75b2ff587668caa9d7c9f0623f8469559f2c01890f98ce = 14, https://openthread.io/reference/group/plat-logging#group__plat-logging_1ggaee25d56d067df60b93f75b2ff587668cabd9948e6e1ae9eb93219b2635fcd37db = 15, https://openthread.io/reference/group/plat-logging#group__plat-logging_1ggaee25d56d067df60b93f75b2ff587668cacca68dba35ed03bbc0d7ab03f9169186 = 16, https://openthread.io/reference/group/plat-logging#group__plat-logging_1ggaee25d56d067df60b93f75b2ff587668cab8366e9bda05e7e04ce69bd77ff9d31f = 17, https://openthread.io/reference/group/plat-logging#group__plat-logging_1ggaee25d56d067df60b93f75b2ff587668cab982e4616d0eccc6ab28fd7ed1557757 = 18, https://openthread.io/reference/group/plat-logging#group__plat-logging_1ggaee25d56d067df60b93f75b2ff587668ca801dcf754043ee998976329bdd40bd90 = 19, https://openthread.io/reference/group/plat-logging#group__plat-logging_1ggaee25d56d067df60b93f75b2ff587668ca94d2803fb611b7876ccc80d28799f9e2 = 20, https://openthread.io/reference/group/plat-logging#group__plat-logging_1ggaee25d56d067df60b93f75b2ff587668cae0ebd6f73d2312f69a787a0e18c51091 = 21, https://openthread.io/reference/group/plat-logging#group__plat-logging_1ggaee25d56d067df60b93f75b2ff587668cab6cd9d6bd9d8611a4e0ebf09f738a029 = 22, https://openthread.io/reference/group/plat-logging#group__plat-logging_1ggaee25d56d067df60b93f75b2ff587668ca894cc8b968b5986c09a7eb0b9986e5e4 = 23 }` | enumRepresents log regions. |

| ### Typedefs ||
|---|---|
| `https://openthread.io/reference/group/plat-logging#group__plat-logging_1ga6ac756046db5c24c6c068139b689dbdb` | typedef `int` Represents the log level. |
| `https://openthread.io/reference/group/plat-logging#group__plat-logging_1ga808e7871ed75a73318c4228f404486e0` | typedef `enum https://openthread.io/reference/group/plat-logging#group__plat-logging_1gaee25d56d067df60b93f75b2ff587668c` Represents log regions. |

| ### Functions ||
|---|---|
| `https://openthread.io/reference/group/plat-logging#group__plat-logging_1gada6f3e6235ef97eb169bccb45755fd5a(https://openthread.io/reference/group/plat-logging#group__plat-logging_1ga6ac756046db5c24c6c068139b689dbdb aLogLevel, https://openthread.io/reference/group/plat-logging#group__plat-logging_1gaee25d56d067df60b93f75b2ff587668c aLogRegion, const char *aFormat, ...)` | `void` Outputs logs. |
| `https://openthread.io/reference/group/plat-logging#group__plat-logging_1ga14b6a398e62760168979d5e7a0310c4e(https://openthread.io/reference/group/plat-logging#group__plat-logging_1ga6ac756046db5c24c6c068139b689dbdb aLogLevel)` | `void` Handles OpenThread log level changes. |
| `https://openthread.io/reference/group/plat-logging#group__plat-logging_1ga187c8432a51e3d0c26b938034400ed02(https://openthread.io/reference/group/api-instance#group__api-instance_1ga25440551213fb5b40869725378584960 *aInstance, https://openthread.io/reference/group/plat-logging#group__plat-logging_1ga6ac756046db5c24c6c068139b689dbdb aLogLevel)` | `void` Handles OpenThread instance-specific log level changes. |
| `https://openthread.io/reference/group/plat-logging#group__plat-logging_1ga40af839c22ea38ec4de27682941772b8(https://openthread.io/reference/group/api-instance#group__api-instance_1ga25440551213fb5b40869725378584960 *aInstance, https://openthread.io/reference/group/plat-logging#group__plat-logging_1ga6ac756046db5c24c6c068139b689dbdb aLogLevel, const char *aLogLine)` | `void` Outputs a log line. |

| ### Macros ||
|---|---|
| `https://openthread.io/reference/group/plat-logging#group__plat-logging_1ga45e13bc61de33b7b69dcea2cd7a2e3d9 1` | Log level Critical. |
| `https://openthread.io/reference/group/plat-logging#group__plat-logging_1ga2bafd1269d6e2223b0d86e782b5ca123 5` | Log level Debug. |
| `https://openthread.io/reference/group/plat-logging#group__plat-logging_1ga5d7749dcdebf56aa96aca267c6d4f8c8 4` | Log level Informational. |
| `https://openthread.io/reference/group/plat-logging#group__plat-logging_1ga987f77155965c0df144959c8425acece 0` | Log level None. |
| `https://openthread.io/reference/group/plat-logging#group__plat-logging_1ga55a13904ca3f95aaee003abbda819848 3` | Log level Notice. |
| `https://openthread.io/reference/group/plat-logging#group__plat-logging_1ga1124e3c83ea474c959435b3922484806 2` | Log level Warning. |

## Enumerations

### otLogRegion

```
 otLogRegion
```
Represents log regions.

The support for log region is removed and instead each core module can define its own name to appended to the logs. However, the `otLogRegion` enumeration is still defined as before to help with platforms which we may be using it in their `https://openthread.io/reference/group/plat-logging#group__plat-logging_1gada6f3e6235ef97eb169bccb45755fd5a` implementation. The OT core will always emit all logs with `OT_LOG_REGION_CORE`.

| Properties ||
|---|---|
| `OT_LOG_REGION_API` | OpenThread API. |
| `OT_LOG_REGION_ARP` | EID-to-RLOC mapping. |
| `OT_LOG_REGION_BBR` | Backbone Router (available since Thread 1.2) |
| `OT_LOG_REGION_BR` | Border Router. |
| `OT_LOG_REGION_CLI` | CLI. |
| `OT_LOG_REGION_COAP` | CoAP. |
| `OT_LOG_REGION_CORE` | OpenThread Core. |
| `OT_LOG_REGION_DNS` | DNS. |
| `OT_LOG_REGION_DUA` | Domain Unicast Address (available since Thread 1.2) |
| `OT_LOG_REGION_ICMP` | ICMPv6. |
| `OT_LOG_REGION_IP6` | IPv6. |
| `OT_LOG_REGION_MAC` | IEEE 802.15.4 MAC. |
| `OT_LOG_REGION_MEM` | Memory. |
| `OT_LOG_REGION_MESH_COP` | Mesh Commissioning Protocol. |
| `OT_LOG_REGION_MLE` | MLE. |
| `OT_LOG_REGION_MLR` | Multicast Listener Registration (available since Thread 1.2) |
| `OT_LOG_REGION_NCP` | NCP. |
| `OT_LOG_REGION_NET_DATA` | Network Data. |
| `OT_LOG_REGION_NET_DIAG` | Network Diagnostic. |
| `OT_LOG_REGION_PLATFORM` | Platform. |
| `OT_LOG_REGION_SRP` | Service Registration Protocol (SRP) |
| `OT_LOG_REGION_TCP` | TCP. |
| `OT_LOG_REGION_UTIL` | Utility module. |

## Typedefs

### otLogLevel

```
int otLogLevel
```
Represents the log level.

### otLogRegion

```
enum otLogRegion otLogRegion
```
Represents log regions.

The support for log region is removed and instead each core module can define its own name to appended to the logs. However, the `otLogRegion` enumeration is still defined as before to help with platforms which we may be using it in their `https://openthread.io/reference/group/plat-logging#group__plat-logging_1gada6f3e6235ef97eb169bccb45755fd5a` implementation. The OT core will always emit all logs with `OT_LOG_REGION_CORE`.

## Functions

### otPlatLog

```
void otPlatLog(
  otLogLevel aLogLevel,
  otLogRegion aLogRegion,
  const char *aFormat,
  ...
)
```
Outputs logs.

This platform API is used to output logs when the configuration `OPENTHREAD_CONFIG_LOG_INSTANCE_AWARE_API_ENABLE` is disabled. When the configuration is enabled, `https://openthread.io/reference/group/plat-logging#group__plat-logging_1ga40af839c22ea38ec4de27682941772b8` is used instead.

Note that the support for log region is removed. The OT core will always emit all logs with `OT_LOG_REGION_CORE` as `aLogRegion`.

<br />

| Details ||
|---|---|
| Parameters | |---|---| | `[in] aLogLevel` | The log level. | | `[in] aLogRegion` | The log region. | | `[in] aFormat` | A pointer to the format string. | | `[in] ...` | Arguments for the format specification. | |

### otPlatLogHandleLevelChanged

```
void otPlatLogHandleLevelChanged(
  otLogLevel aLogLevel
)
```
Handles OpenThread log level changes.

This platform function is optional. An empty weak implementation is provided by OpenThread core.

This platform function is called whenever the OpenThread log level changes:

- In a single-instance configuration, this is called when the log level changes.
- In a multi-instance configuration, this is called when the global log level changes.

<br />


> [!NOTE]
> **Note:** Only applicable when `OPENTHREAD_CONFIG_LOG_LEVEL_DYNAMIC_ENABLE=1`.

<br />

| Details ||
|---|---|
| Parameters | |---|---| | `[in] aLogLevel` | The new OpenThread log level. | |

### otPlatLogHandleLogLevelChanged

```
void otPlatLogHandleLogLevelChanged(
  otInstance *aInstance,
  otLogLevel aLogLevel
)
```
Handles OpenThread instance-specific log level changes.

This platform function is optional. An empty weak implementation is provided by OpenThread core.

This platform function is called whenever the instance-specific log level changes:

- In a single-instance configuration, this is called along with `https://openthread.io/reference/group/plat-logging#group__plat-logging_1ga14b6a398e62760168979d5e7a0310c4e`.
- In a multi-instance configuration, if `OPENTHREAD_CONFIG_LOG_INSTANCE_AWARE_API_ENABLE` is used, this is called when the instance-specific log level changes.

<br />

<br />

| Details ||
|---|---|
| Parameters | |---|---| | `[in] aInstance` | A pointer to the OpenThread instance. | | `[in] aLogLevel` | The new OpenThread log level for the instance. | |

### otPlatLogOutput

```
void otPlatLogOutput(
  otInstance *aInstance,
  otLogLevel aLogLevel,
  const char *aLogLine
)
```
Outputs a log line.

This platform API is an alternative to `https://openthread.io/reference/group/plat-logging#group__plat-logging_1gada6f3e6235ef97eb169bccb45755fd5a` and is used when the configuration `OPENTHREAD_CONFIG_LOG_INSTANCE_AWARE_API_ENABLE` is enabled.

Unlike `https://openthread.io/reference/group/plat-logging#group__plat-logging_1gada6f3e6235ef97eb169bccb45755fd5a`, this API also provides a pointer to the OpenThread instance (`otInstance*`) from which the log is generated. This is particularly helpful in a multi-instance setup to distinguish logs from different instances. Additionally, it provides the log line as a fully formatted null-terminated string instead of a format string and variable arguments.

<br />

| Details ||
|---|---|
| Parameters | |---|---| | `[in] aInstance` | A pointer to the OpenThread instance. | | `[in] aLogLevel` | The log level. | | `[in] aLogLine` | A pointer to the null-terminated string containing the log line. | |

## Macros

### OT_LOG_LEVEL_CRIT

```
 OT_LOG_LEVEL_CRIT 1
```
Log level Critical.


> [!NOTE]
> **Note:** Log Levels are defines so that embedded implementations can eliminate code at compile time via #if/#else/#endif.

<br />

### OT_LOG_LEVEL_DEBG

```
 OT_LOG_LEVEL_DEBG 5
```
Log level Debug.


> [!NOTE]
> **Note:** Log Levels are defines so that embedded implementations can eliminate code at compile time via #if/#else/#endif.

<br />

### OT_LOG_LEVEL_INFO

```
 OT_LOG_LEVEL_INFO 4
```
Log level Informational.


> [!NOTE]
> **Note:** Log Levels are defines so that embedded implementations can eliminate code at compile time via #if/#else/#endif.

<br />

### OT_LOG_LEVEL_NONE

```
 OT_LOG_LEVEL_NONE 0
```
Log level None.


> [!NOTE]
> **Note:** Log Levels are defines so that embedded implementations can eliminate code at compile time via #if/#else/#endif.

<br />

### OT_LOG_LEVEL_NOTE

```
 OT_LOG_LEVEL_NOTE 3
```
Log level Notice.


> [!NOTE]
> **Note:** Log Levels are defines so that embedded implementations can eliminate code at compile time via #if/#else/#endif.

<br />

### OT_LOG_LEVEL_WARN

```
 OT_LOG_LEVEL_WARN 2
```
Log level Warning.


> [!NOTE]
> **Note:** Log Levels are defines so that embedded implementations can eliminate code at compile time via #if/#else/#endif.

<br />

## Resources

OpenThread API Reference topics originate from the source code, available
on [GitHub](https://github.com/openthread/openthread/tree/main/include/openthread).
For more information, or to contribute to our documentation, refer to
[Resources](https://openthread.io/resources).