---
title: "Log levels"
canonical_url: https://developer.repebble.com/pebbleos/docs/samples/subsys/logging/levels/
last_updated: 2026-11-18
sdk_version: 4.44
---
# Log levels

Source: https://developer.repebble.com/pebbleos/docs/samples/subsys/logging/levels/

This sample has a [log module](https://developer.repebble.com/pebbleos/docs/subsystems/logging.md) of its own. Its `Kconfig` sources the log level template, which defines `CONFIG_SAMPLE_LOG_LEVEL` and `CONFIG_SAMPLE_LOG_LEVEL_RUNTIME`; `prj.conf` picks the debug level, and `src/sensor.c` joins the module with `PBL_LOG_MODULE_DECLARE()`.

It logs once at each level: the verbose message is dropped. With a runtime level, `PBL_LOG_MODULE_LEVEL_SET()` then raises it to warnings, and only the error and the warning remain. Without one, the level is fixed when building, and messages above it are not even in the image.

Run:

`pbl samples samples/subsys/logging/levels`

Boards:

every board

## Sources

Kconfig

```
mainmenu "Logging sample"

source "Kconfig.pebbleos"

module = SAMPLE
module-str = Sample
source "subsys/logging/Kconfig.template.log_level"
```

prj.conf

```
CONFIG_CONSOLE=y
CONFIG_CONSOLE_STDOUT=y
CONFIG_LOG=y
CONFIG_SAMPLE_LOG_LEVEL_DEBUG=y
CONFIG_SAMPLE_LOG_LEVEL_RUNTIME=y
```

src/main.c

```
#include "sensor.h"#include \<stdint.h\>#include \<stdio.h\>#include \<pbl/logging/logging.h\>/\* The sample's Kconfig defines CONFIG\_SAMPLE\_LOG\_LEVEL from the log level template. \*/PBL\_LOG\_MODULE\_DEFINE(sample, CONFIG\_SAMPLE\_LOG\_LEVEL);static void prv\_log\_each\_level(void) {PBL\_LOG\_ERR("an error");PBL\_LOG\_WRN("a warning");PBL\_LOG\_INFO("an event worth attention");PBL\_LOG\_DBG("a routine state change");PBL\_LOG\_VERBOSE("a detail");}int main(void) {uint8\_t data[16];/\* The module starts at its configured level, debug: verbose messages are dropped. \*/prv\_log\_each\_level();if (sensor\_read(data, sizeof(data)) == 0) {PBL\_LOG\_HEXDUMP\_INFO(data, sizeof(data));}(void)sensor\_read(data, 32U);/\* Built with CONFIG\_SAMPLE\_LOG\_LEVEL\_RUNTIME, the level can change while running. \*/PBL\_LOG\_MODULE\_LEVEL\_SET(sample, LOG\_LEVEL\_WARNING);PBL\_LOG\_WRN("level now %d, warning", PBL\_LOG\_MODULE\_LEVEL\_GET(sample));prv\_log\_each\_level();printf("Sample done\n");return 0;}
```

src/sensor.c

```
#include "sensor.h"#include \<errno.h\>#include \<pbl/logging/logging.h\>/\* Another file of the same module: it shares its level. \*/PBL\_LOG\_MODULE\_DECLARE(sample, CONFIG\_SAMPLE\_LOG\_LEVEL);int sensor\_read(uint8\_t \*buf, size\_t len) {if (len \> 16U) {PBL\_LOG\_WRN("read of %zu bytes, at most 16", len);return -EINVAL;}for (size\_t i = 0; i \< len; i++) {buf[i] = (uint8\_t)(0xa0U + i);}PBL\_LOG\_DBG("read %zu bytes", len);return 0;}
```

## Output

```
E .* sample: an error
W .* sample: a warning
I .* sample: an event worth attention
D .* sample: a routine state change
D .* sample: read 16 bytes
I .* 0000 a0 a1 a2 a3 a4 a5 a6 a7 a8 a9 aa ab ac ad ae af
W .* sample: read of 32 bytes, at most 16
W .* sample: level now 50, warning
E .* sample: an error
W .* sample: a warning
Sample done
```

Generated from PebbleOS [7753e801d](https://github.com/coredevices/pebbleos/commit/7753e801d93d20f2d37534ce2fa69d9952015237). This page is maintained in the pebbleos repository: [docs/samples/subsys/logging/levels.md](https://github.com/coredevices/pebbleos/blob/7753e801d93d20f2d37534ce2fa69d9952015237/docs/samples/subsys/logging/levels.md).
