Skip to content

Commit

Permalink
log: make name param explicit
Browse files Browse the repository at this point in the history
Rather than having some implied name for the logging name, explicitly
pass it in the macros LOG_MODULE_REGISTER & LOG_MODULE_DECLARE.

Signed-off-by: Kumar Gala <kumar.gala@linaro.org>
  • Loading branch information
galak committed Aug 15, 2018
1 parent 39cb4b4 commit 2cb17a0
Show file tree
Hide file tree
Showing 6 changed files with 14 additions and 13 deletions.
6 changes: 2 additions & 4 deletions doc/subsystems/logging/logger.rst
Expand Up @@ -145,21 +145,19 @@ module can be specified as well.

.. code-block:: c
#define LOG_MODULE_NAME foo
#define LOG_LEVEL CONFIG_FOO_LOG_LEVEL /* From foo module Kconfig */
#include <logging/log.h>
LOG_MODULE_REGISTER(); /* One per given LOG_MODULE_NAME */
LOG_MODULE_REGISTER(foo); /* One per given log_module_name */
If the module consists of multiple files, then ``LOG_MODULE_REGISTER()`` should
appear in exactly one of them. Each other file should use
:c:macro:`LOG_MODULE_DECLARE` to declare its membership in the module.

.. code-block:: c
#define LOG_MODULE_NAME foo
#define LOG_LEVEL CONFIG_FOO_LOG_LEVEL /* From foo module Kconfig */
#include <logging/log.h>
LOG_MODULE_DECLARE(); /* In all files comprising the module but one */
LOG_MODULE_DECLARE(foo); /* In all files comprising the module but one */
Logging in a module instance
============================
Expand Down
8 changes: 4 additions & 4 deletions include/logging/log.h
Expand Up @@ -298,10 +298,10 @@ int log_printk(const char *fmt, va_list ap);
* In other cases, this macro has no effect.
* @see LOG_MODULE_DECLARE
*/
#define LOG_MODULE_REGISTER() \
#define LOG_MODULE_REGISTER(log_module_name) \
_LOG_EVAL( \
_LOG_LEVEL(), \
(_LOG_MODULE_REGISTER(LOG_MODULE_NAME, _LOG_LEVEL())), \
(_LOG_MODULE_REGISTER(log_module_name, _LOG_LEVEL())), \
()/*Empty*/ \
)

Expand Down Expand Up @@ -336,10 +336,10 @@ int log_printk(const char *fmt, va_list ap);
* this macro has no effect.
* @see LOG_MODULE_REGISTER
*/
#define LOG_MODULE_DECLARE() \
#define LOG_MODULE_DECLARE(log_module_name) \
_LOG_EVAL( \
_LOG_LEVEL(), \
(_LOG_MODULE_DECLARE(LOG_MODULE_NAME, _LOG_LEVEL())), \
(_LOG_MODULE_DECLARE(log_module_name, _LOG_LEVEL())), \
() \
) \

Expand Down
3 changes: 2 additions & 1 deletion samples/subsys/logging/logger/src/ext_log_system_adapter.c
Expand Up @@ -9,7 +9,8 @@

#define LOG_MODULE_NAME ext_log_system
#include <logging/log.h>
LOG_MODULE_REGISTER();

LOG_MODULE_REGISTER(ext_log_system);

/** @brief Translation of custom log levels to logging subsystem levels. */
static const u8_t log_level_lut[] = {
Expand Down
4 changes: 2 additions & 2 deletions samples/subsys/logging/logger/src/main.c
Expand Up @@ -14,9 +14,9 @@
#include "ext_log_system.h"
#include "ext_log_system_adapter.h"

#define LOG_MODULE_NAME main
#include <logging/log.h>
LOG_MODULE_REGISTER();

LOG_MODULE_REGISTER(main);

/* size of stack area used by each thread */
#define STACKSIZE 1024
Expand Down
3 changes: 2 additions & 1 deletion samples/subsys/logging/logger/src/sample_module.c
Expand Up @@ -7,7 +7,8 @@

#define LOG_MODULE_NAME foo
#include <logging/log.h>
LOG_MODULE_REGISTER();

LOG_MODULE_REGISTER(LOG_MODULE_NAME);

const char *sample_module_name_get(void)
{
Expand Down
3 changes: 2 additions & 1 deletion tests/subsys/logging/log_core/src/log_core_test.c
Expand Up @@ -20,7 +20,8 @@

#define LOG_MODULE_NAME test
#include "logging/log.h"
LOG_MODULE_REGISTER();

LOG_MODULE_REGISTER(LOG_MODULE_NAME);

struct backend_cb {
size_t counter;
Expand Down

0 comments on commit 2cb17a0

Please sign in to comment.