Hint

Refer to QMK’s documentation for details on how to use community modules

logging

Custom logging utilities, inspired by Python’s logging module.

Note

Under the hood, this is just a wrapper on top of printf().

Default format for logging messages.

enum log_level_t
[source]

Different level of severity. Used to filter out messages.

Warning

If you want to add a new one, it has to be the last element.

enumerator LOG_DEBUG
[source]
enumerator LOG_INFO
[source]
enumerator LOG_WARN
[source]
enumerator LOG_ERROR
[source]
enumerator LOG_NONE
[source]

Hint

The logging() function will apply an extra transformation to your input, based on a custom format. Its specifiers being:

  • %LL: The message’s level (long). Eg: DEBUG.

    • These strings are set in level_str.

  • %LS: Print only the first char of the previous string. Eg: D.

  • %M: The actual message created by msg and ... passed to logging(). With its regular format.

  • %T: Current time, you can override log_time() to hook it with a RTC or whatever.

    • Default implementation is seconds since boot.

  • %%: Write a literal %.

For example, with format of [%LL] %T -- %M, messages would look like: [DEBUG] 3s -- Formatted message

log_level_t get_logging_level(void)
[source]

Get the current level. Messages with a lower severity are dropped.

void set_logging_level(log_level_t level)
[source]

Change the current level.

void step_logging_level(bool increase)
[source]

Increase (or decrease) by one the level.

The direction is based on increase.

Attention

From this point, the functions are mostly implementation details.

You, most likely, don’t need to know anything about them.

log_level_t get_current_message_level(void)
[source]

Get the severity of the message being emitted.

This may be used by a sendchar_func_t internally.

const char *log_time(void)
[source]

Get a string representing the current time.

By default, seconds since boot, but it can be overwritten.

ASSERT_LEVELS(__array)
[source]

Check that an array has as many elements as logging levels are defined.

If not, compilation will error out.