Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions doc/subsystems/logging/logger.rst
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,17 @@ appear in exactly one of them. Each other file should use
#include <logging/log.h>
LOG_MODULE_DECLARE(foo); /* In all files comprising the module but one */

Dedicated Kconfig template (:file:`subsys/logging/Kconfig.template.log_config`)
can be used to create local log level configuration.

Example below presents usage of the template. As a result CONFIG_FOO_LOG_LEVEL
will be generated:

.. code-block:: none
module = FOO
module-str = foo
source "subsys/logging/Kconfig.template.log_config"

Logging in a module instance
============================

Expand Down
2 changes: 2 additions & 0 deletions samples/subsys/logging/logger/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
cmake_minimum_required(VERSION 3.8.2)

set(KCONFIG_ROOT ${CMAKE_CURRENT_SOURCE_DIR}/Kconfig)

include($ENV{ZEPHYR_BASE}/cmake/app/boilerplate.cmake NO_POLICY_SCOPE)
project(NONE)

Expand Down
18 changes: 18 additions & 0 deletions samples/subsys/logging/logger/Kconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Kconfig - Config options for logger sample app
#
# Copyright (c) 2018 Nordic Semiconductor ASA
#
# SPDX-License-Identifier: Apache-2.0
#

mainmenu "Logger sample application"

menu "Application configuration"

module = SAMPLE_MODULE
module-str = Sample module
source "subsys/logging/Kconfig.template.log_config"

endmenu

source "$(ZEPHYR_BASE)/Kconfig.zephyr"
4 changes: 2 additions & 2 deletions samples/subsys/logging/logger/src/sample_module.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@
* SPDX-License-Identifier: Apache-2.0
*/
#include <zephyr.h>

#define LOG_MODULE_NAME foo
#include <logging/log.h>

#define LOG_MODULE_NAME sample_module
#define LOG_LEVEL CONFIG_SAMPLE_MODULE_LOG_LEVEL
LOG_MODULE_REGISTER(LOG_MODULE_NAME);

const char *sample_module_name_get(void)
Expand Down
28 changes: 28 additions & 0 deletions subsys/logging/Kconfig.template.log_config
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
choice
prompt "Max compiled-in log level for $(module-str)"
default $(module)_LOG_LEVEL_INF

config $(module)_LOG_LEVEL_OFF
bool "Off"

config $(module)_LOG_LEVEL_ERR
bool "Error"

config $(module)_LOG_LEVEL_WRN
bool "Warning"

config $(module)_LOG_LEVEL_INF
bool "Info"

config $(module)_LOG_LEVEL_DBG
bool "Debug"

endchoice

config $(module)_LOG_LEVEL
int
default 0 if $(module)_LOG_LEVEL_OFF
default 1 if $(module)_LOG_LEVEL_ERR
default 2 if $(module)_LOG_LEVEL_WRN
default 3 if $(module)_LOG_LEVEL_INF
default 4 if $(module)_LOG_LEVEL_DBG