Skip to content

Commit e54956c

Browse files
committed
log: make name param explicit
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 <[email protected]> Signed-off-by: Krzysztof Chruscinski <[email protected]>
1 parent ea4f8b7 commit e54956c

File tree

10 files changed

+31
-23
lines changed

10 files changed

+31
-23
lines changed

doc/subsystems/logging/logger.rst

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -145,21 +145,19 @@ module can be specified as well.
145145

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

157156
.. code-block:: c
158157
159-
#define LOG_MODULE_NAME foo
160158
#define LOG_LEVEL CONFIG_FOO_LOG_LEVEL /* From foo module Kconfig */
161159
#include <logging/log.h>
162-
LOG_MODULE_DECLARE(); /* In all files comprising the module but one */
160+
LOG_MODULE_DECLARE(foo); /* In all files comprising the module but one */
163161
164162
Logging in a module instance
165163
============================

include/logging/log.h

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -261,7 +261,12 @@ int log_printk(const char *fmt, va_list ap);
261261
__attribute__ ((section("." STRINGIFY( \
262262
LOG_ITEM_DYNAMIC_DATA(_name)))) \
263263
) \
264-
__attribute__((used))
264+
__attribute__((used)); \
265+
static inline const struct log_source_dynamic_data * \
266+
__log_current_dynamic_data_get(void) \
267+
{ \
268+
return &LOG_ITEM_DYNAMIC_DATA(_name); \
269+
}
265270

266271
#define _LOG_RUNTIME_MODULE_REGISTER(_name) \
267272
_LOG_EVAL( \
@@ -277,7 +282,12 @@ int log_printk(const char *fmt, va_list ap);
277282
.name = STRINGIFY(_name), \
278283
.level = _level \
279284
} \
280-
_LOG_RUNTIME_MODULE_REGISTER(_name)
285+
_LOG_RUNTIME_MODULE_REGISTER(_name); \
286+
static inline const struct log_source_const_data * \
287+
__log_current_const_data_get(void) \
288+
{ \
289+
return &LOG_ITEM_CONST_DATA(_name); \
290+
}
281291

282292
/**
283293
* @brief Create module-specific state and register the module with Logger.
@@ -298,10 +308,10 @@ int log_printk(const char *fmt, va_list ap);
298308
* In other cases, this macro has no effect.
299309
* @see LOG_MODULE_DECLARE
300310
*/
301-
#define LOG_MODULE_REGISTER() \
311+
#define LOG_MODULE_REGISTER(log_module_name) \
302312
_LOG_EVAL( \
303313
_LOG_LEVEL(), \
304-
(_LOG_MODULE_REGISTER(LOG_MODULE_NAME, _LOG_LEVEL())), \
314+
(_LOG_MODULE_REGISTER(log_module_name, _LOG_LEVEL())), \
305315
()/*Empty*/ \
306316
)
307317

@@ -336,10 +346,10 @@ int log_printk(const char *fmt, va_list ap);
336346
* this macro has no effect.
337347
* @see LOG_MODULE_REGISTER
338348
*/
339-
#define LOG_MODULE_DECLARE() \
349+
#define LOG_MODULE_DECLARE(log_module_name) \
340350
_LOG_EVAL( \
341351
_LOG_LEVEL(), \
342-
(_LOG_MODULE_DECLARE(LOG_MODULE_NAME, _LOG_LEVEL())), \
352+
(_LOG_MODULE_DECLARE(log_module_name, _LOG_LEVEL())), \
343353
() \
344354
) \
345355

include/logging/log_core.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ extern "C" {
9898
#define LOG_CURRENT_MODULE_ID() \
9999
_LOG_EVAL( \
100100
_LOG_LEVEL(), \
101-
(log_const_source_id(&LOG_ITEM_CONST_DATA(LOG_MODULE_NAME))), \
101+
(log_const_source_id(__log_current_const_data_get())), \
102102
(0) \
103103
)
104104

@@ -109,7 +109,7 @@ extern "C" {
109109
#define LOG_CURRENT_DYNAMIC_DATA_ADDR() \
110110
_LOG_EVAL( \
111111
_LOG_LEVEL(), \
112-
(&LOG_ITEM_DYNAMIC_DATA(LOG_MODULE_NAME)), \
112+
(__log_current_dynamic_data_get()), \
113113
((struct log_source_dynamic_data *)0) \
114114
)
115115

samples/subsys/logging/logger/src/ext_log_system_adapter.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@
99

1010
#define LOG_MODULE_NAME ext_log_system
1111
#include <logging/log.h>
12-
LOG_MODULE_REGISTER();
12+
13+
LOG_MODULE_REGISTER(ext_log_system);
1314

1415
/** @brief Translation of custom log levels to logging subsystem levels. */
1516
static const u8_t log_level_lut[] = {

samples/subsys/logging/logger/src/main.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,9 @@
1414
#include "ext_log_system.h"
1515
#include "ext_log_system_adapter.h"
1616

17-
#define LOG_MODULE_NAME main
1817
#include <logging/log.h>
19-
LOG_MODULE_REGISTER();
18+
19+
LOG_MODULE_REGISTER(main);
2020

2121
/* size of stack area used by each thread */
2222
#define STACKSIZE 1024

samples/subsys/logging/logger/src/sample_module.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@
77

88
#define LOG_MODULE_NAME foo
99
#include <logging/log.h>
10-
LOG_MODULE_REGISTER();
10+
11+
LOG_MODULE_REGISTER(LOG_MODULE_NAME);
1112

1213
const char *sample_module_name_get(void)
1314
{

subsys/power/device.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,9 @@
1111
#include <device.h>
1212
#include "pm_policy.h"
1313

14-
#define LOG_MODULE_NAME power
1514
#define LOG_LEVEL CONFIG_PM_LOG_LEVEL /* From power module Kconfig */
1615
#include <logging/log.h>
17-
LOG_MODULE_DECLARE();
16+
LOG_MODULE_DECLARE(power);
1817

1918
/*
2019
* FIXME: Remove the conditional inclusion of

subsys/power/policy.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,9 @@
99
#include <soc.h>
1010
#include "pm_policy.h"
1111

12-
#define LOG_MODULE_NAME power
1312
#define LOG_LEVEL CONFIG_PM_LOG_LEVEL /* From power module Kconfig */
1413
#include <logging/log.h>
15-
LOG_MODULE_DECLARE();
14+
LOG_MODULE_DECLARE(power);
1615

1716
#ifdef CONFIG_TICKLESS_KERNEL
1817
#define SECS_TO_TICKS CONFIG_TICKLESS_KERNEL_TIME_UNIT_IN_MICRO_SECS

subsys/power/power.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,9 @@
1111
#include <soc.h>
1212
#include "pm_policy.h"
1313

14-
#define LOG_MODULE_NAME power
1514
#define LOG_LEVEL CONFIG_PM_LOG_LEVEL /* From power module Kconfig */
1615
#include <logging/log.h>
17-
LOG_MODULE_REGISTER();
16+
LOG_MODULE_REGISTER(power);
1817

1918
static int post_ops_done = 1;
2019
static enum power_states pm_state;

tests/subsys/logging/log_core/src/log_core_test.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,8 @@
2020

2121
#define LOG_MODULE_NAME test
2222
#include "logging/log.h"
23-
LOG_MODULE_REGISTER();
23+
24+
LOG_MODULE_REGISTER(LOG_MODULE_NAME);
2425

2526
struct backend_cb {
2627
size_t counter;

0 commit comments

Comments
 (0)