mirror of
https://github.com/RIOT-OS/RIOT.git
synced 2024-12-29 04:50:03 +01:00
sys/log: modularize log into log_color and log_printfnoformat
- log_color: make log_write nonstatic - log_printfnoformat - apply module split to Kconfig
This commit is contained in:
parent
b35a291332
commit
514325b8b3
@ -175,8 +175,6 @@ PSEUDOMODULES += l2filter_blacklist
|
|||||||
PSEUDOMODULES += l2filter_whitelist
|
PSEUDOMODULES += l2filter_whitelist
|
||||||
PSEUDOMODULES += libstdcpp
|
PSEUDOMODULES += libstdcpp
|
||||||
PSEUDOMODULES += log
|
PSEUDOMODULES += log
|
||||||
PSEUDOMODULES += log_printfnoformat
|
|
||||||
PSEUDOMODULES += log_color
|
|
||||||
PSEUDOMODULES += lora
|
PSEUDOMODULES += lora
|
||||||
## @defgroup pseudomodule_libc_gettimeofday libc_gettimeofday
|
## @defgroup pseudomodule_libc_gettimeofday libc_gettimeofday
|
||||||
## @brief Includes implementation of gettimeofday()
|
## @brief Includes implementation of gettimeofday()
|
||||||
|
16
sys/Kconfig
16
sys/Kconfig
@ -64,8 +64,16 @@ rsource "Kconfig.picolibc"
|
|||||||
|
|
||||||
endmenu # Libc
|
endmenu # Libc
|
||||||
|
|
||||||
|
|
||||||
rsource "Kconfig.stdio"
|
rsource "Kconfig.stdio"
|
||||||
rsource "log/Kconfig"
|
choice LOG
|
||||||
|
bool "Logging system override"
|
||||||
|
optional
|
||||||
|
#modules log_color and log_printfnoformat describe their options
|
||||||
|
endchoice
|
||||||
|
|
||||||
|
rsource "log_color/Kconfig"
|
||||||
|
rsource "log_printfnoformat/Kconfig"
|
||||||
rsource "luid/Kconfig"
|
rsource "luid/Kconfig"
|
||||||
rsource "malloc_thread_safe/Kconfig"
|
rsource "malloc_thread_safe/Kconfig"
|
||||||
rsource "matstat/Kconfig"
|
rsource "matstat/Kconfig"
|
||||||
@ -124,4 +132,10 @@ config MODULE_SYS
|
|||||||
help
|
help
|
||||||
System module, it serves to pull in all the rest of system modules.
|
System module, it serves to pull in all the rest of system modules.
|
||||||
|
|
||||||
|
config MODULE_LOG
|
||||||
|
bool
|
||||||
|
help
|
||||||
|
Modules that override the default log implementation should select this.
|
||||||
|
For more information see core/include/log.h.
|
||||||
|
|
||||||
endmenu # System
|
endmenu # System
|
||||||
|
@ -104,9 +104,6 @@ endif
|
|||||||
ifneq (,$(filter l2util,$(USEMODULE)))
|
ifneq (,$(filter l2util,$(USEMODULE)))
|
||||||
DIRS += net/link_layer/l2util
|
DIRS += net/link_layer/l2util
|
||||||
endif
|
endif
|
||||||
ifneq (,$(filter log_%,$(USEMODULE)))
|
|
||||||
DIRS += log
|
|
||||||
endif
|
|
||||||
ifneq (,$(filter nanocoap,$(USEMODULE)))
|
ifneq (,$(filter nanocoap,$(USEMODULE)))
|
||||||
DIRS += net/application_layer/nanocoap
|
DIRS += net/application_layer/nanocoap
|
||||||
endif
|
endif
|
||||||
|
@ -74,8 +74,12 @@ ifneq (,$(filter embunit,$(USEMODULE)))
|
|||||||
endif
|
endif
|
||||||
endif
|
endif
|
||||||
|
|
||||||
ifneq (,$(filter log_%,$(USEMODULE)))
|
ifneq (,$(filter log_color,$(USEMODULE)))
|
||||||
include $(RIOTBASE)/sys/log/Makefile.include
|
include $(RIOTBASE)/sys/log_color/Makefile.include
|
||||||
|
endif
|
||||||
|
|
||||||
|
ifneq (,$(filter log_printfnoformat,$(USEMODULE)))
|
||||||
|
include $(RIOTBASE)/sys/log_printfnoformat/Makefile.include
|
||||||
endif
|
endif
|
||||||
|
|
||||||
ifneq (,$(filter newlib,$(USEMODULE)))
|
ifneq (,$(filter newlib,$(USEMODULE)))
|
||||||
|
@ -1,36 +0,0 @@
|
|||||||
# Copyright (c) 2021 HAW Hamburg
|
|
||||||
#
|
|
||||||
# This file is subject to the terms and conditions of the GNU Lesser
|
|
||||||
# General Public License v2.1. See the file LICENSE in the top level
|
|
||||||
# directory for more details.
|
|
||||||
#
|
|
||||||
|
|
||||||
choice
|
|
||||||
bool "Logging system override"
|
|
||||||
optional
|
|
||||||
depends on TEST_KCONFIG
|
|
||||||
help
|
|
||||||
Say y to override the default logging functions. For more information see
|
|
||||||
core/include/log.h.
|
|
||||||
|
|
||||||
config MODULE_LOG_COLOR
|
|
||||||
bool "Colored output"
|
|
||||||
select MODULE_LOG
|
|
||||||
help
|
|
||||||
Implements a logging module with colored output.
|
|
||||||
|
|
||||||
config MODULE_LOG_PRINTFNOFORMAT
|
|
||||||
bool "puts-based log"
|
|
||||||
select MODULE_LOG
|
|
||||||
help
|
|
||||||
Logging is implemented using puts instead of printf. Use it where printf
|
|
||||||
might be too heavy. This also serves as an example for logging
|
|
||||||
implementation.
|
|
||||||
|
|
||||||
endchoice
|
|
||||||
|
|
||||||
config MODULE_LOG
|
|
||||||
bool
|
|
||||||
help
|
|
||||||
Modules that override the default log implementation shoul select this.
|
|
||||||
For more information see core/include/log.h.
|
|
@ -1,3 +0,0 @@
|
|||||||
DIRS += $(dir $(wildcard $(addsuffix /Makefile, $(USEMODULE))))
|
|
||||||
|
|
||||||
include $(RIOTBASE)/Makefile.base
|
|
@ -1,19 +0,0 @@
|
|||||||
# check that one, and only one log backend is being used
|
|
||||||
USED_LOG_BACKENDS := $(sort $(filter log_%,$(USEMODULE)))
|
|
||||||
|
|
||||||
ifeq (0,$(words $(USED_LOG_BACKENDS)))
|
|
||||||
$(error The log module is being used but no backend is provided.)
|
|
||||||
else ifeq (1,$(words $(USED_LOG_BACKENDS)))
|
|
||||||
# only one backend is provided, this is correct
|
|
||||||
else
|
|
||||||
$(info Only one log backend can be used at a time.)
|
|
||||||
$(error Currently selecting: $(USED_LOG_BACKENDS))
|
|
||||||
endif
|
|
||||||
|
|
||||||
ifneq (,$(filter log_printfnoformat,$(USEMODULE)))
|
|
||||||
USEMODULE_INCLUDES += $(RIOTBASE)/sys/log/log_printfnoformat
|
|
||||||
endif
|
|
||||||
|
|
||||||
ifneq (,$(filter log_color,$(USEMODULE)))
|
|
||||||
USEMODULE_INCLUDES += $(RIOTBASE)/sys/log/log_color
|
|
||||||
endif
|
|
16
sys/log_color/Kconfig
Normal file
16
sys/log_color/Kconfig
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
# Copyright (c) 2019 HAW Hamburg
|
||||||
|
#
|
||||||
|
# This file is subject to the terms and conditions of the GNU Lesser
|
||||||
|
# General Public License v2.1. See the file LICENSE in the top level
|
||||||
|
# directory for more details.
|
||||||
|
#
|
||||||
|
choice LOG
|
||||||
|
#the choice prompt is described in sys/Kconfig
|
||||||
|
|
||||||
|
config MODULE_LOG_COLOR
|
||||||
|
bool "log_color: colored log output"
|
||||||
|
select MODULE_LOG
|
||||||
|
help
|
||||||
|
Implements a logging module with colored output.
|
||||||
|
|
||||||
|
endchoice
|
1
sys/log_color/Makefile
Normal file
1
sys/log_color/Makefile
Normal file
@ -0,0 +1 @@
|
|||||||
|
include $(RIOTBASE)/Makefile.base
|
1
sys/log_color/Makefile.include
Normal file
1
sys/log_color/Makefile.include
Normal file
@ -0,0 +1 @@
|
|||||||
|
USEMODULE_INCLUDES += $(RIOTBASE)/sys/log_color/include
|
41
sys/log_color/include/log_module.h
Normal file
41
sys/log_color/include/log_module.h
Normal file
@ -0,0 +1,41 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) 2019 Inria
|
||||||
|
*
|
||||||
|
* This file is subject to the terms and conditions of the GNU Lesser
|
||||||
|
* General Public License v2.1. See the file LICENSE in the top level
|
||||||
|
* directory for more details.
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @defgroup sys_log_color log_color: Colored log module
|
||||||
|
* @ingroup sys
|
||||||
|
* @brief This module implements a logging module with colored output
|
||||||
|
* @{
|
||||||
|
*
|
||||||
|
* @file
|
||||||
|
* @brief log_module header
|
||||||
|
*
|
||||||
|
* @author Alexandre Abadie <alexandre.abadie@inria.fr>
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef LOG_MODULE_H
|
||||||
|
#define LOG_MODULE_H
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @brief log_write overridden function for colored output
|
||||||
|
*
|
||||||
|
* @param[in] level Logging level
|
||||||
|
* @param[in] format String format to print
|
||||||
|
*/
|
||||||
|
void log_write(unsigned level, const char *format, ...);
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
#endif /* LOG_MODULE_H */
|
||||||
|
/**@}*/
|
@ -7,30 +7,22 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @defgroup sys_log_color Colored log module
|
* @addtogroup sys_log_color Colored log module
|
||||||
* @ingroup sys
|
|
||||||
* @brief This module implements a logging module with colored output
|
|
||||||
* @{
|
* @{
|
||||||
*
|
*
|
||||||
* @file
|
* @file
|
||||||
* @brief log_module header
|
* @brief log_color
|
||||||
*
|
*
|
||||||
* @author Alexandre Abadie <alexandre.abadie@inria.fr>
|
* @author Alexandre Abadie <alexandre.abadie@inria.fr>
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef LOG_MODULE_H
|
|
||||||
#define LOG_MODULE_H
|
|
||||||
|
|
||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdarg.h>
|
#include <stdarg.h>
|
||||||
|
|
||||||
|
#include "kernel_defines.h"
|
||||||
#include "log.h"
|
#include "log.h"
|
||||||
|
|
||||||
#ifdef __cplusplus
|
|
||||||
extern "C" {
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Default ANSI color escape code for error logs
|
* @brief Default ANSI color escape code for error logs
|
||||||
*
|
*
|
||||||
@ -72,11 +64,6 @@ extern "C" {
|
|||||||
*/
|
*/
|
||||||
#define LOG_RESET_ANSI_COLOR_CODE ("\033[0m")
|
#define LOG_RESET_ANSI_COLOR_CODE ("\033[0m")
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief ANSI color escape codes array
|
|
||||||
*
|
|
||||||
* Internal use only
|
|
||||||
*/
|
|
||||||
static const char * const _ansi_codes[] =
|
static const char * const _ansi_codes[] =
|
||||||
{
|
{
|
||||||
[LOG_ERROR] = LOG_ERROR_ANSI_COLOR_CODE,
|
[LOG_ERROR] = LOG_ERROR_ANSI_COLOR_CODE,
|
||||||
@ -85,15 +72,9 @@ static const char * const _ansi_codes[] =
|
|||||||
[LOG_DEBUG] = LOG_DEBUG_ANSI_COLOR_CODE,
|
[LOG_DEBUG] = LOG_DEBUG_ANSI_COLOR_CODE,
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
void log_write(unsigned level, const char *format, ...)
|
||||||
* @brief log_write overridden function for colored output
|
|
||||||
*
|
|
||||||
* @param[in] level Logging level
|
|
||||||
* @param[in] format String format to print
|
|
||||||
*/
|
|
||||||
static inline void log_write(unsigned level, const char *format, ...)
|
|
||||||
{
|
{
|
||||||
assert(level > 0);
|
assert((level > 0) && (level < ARRAY_SIZE(_ansi_codes)));
|
||||||
|
|
||||||
printf("%s", _ansi_codes[level]);
|
printf("%s", _ansi_codes[level]);
|
||||||
va_list args;
|
va_list args;
|
||||||
@ -110,14 +91,9 @@ static inline void log_write(unsigned level, const char *format, ...)
|
|||||||
va_end(args);
|
va_end(args);
|
||||||
printf(LOG_RESET_ANSI_COLOR_CODE);
|
printf(LOG_RESET_ANSI_COLOR_CODE);
|
||||||
|
|
||||||
#if defined(MODULE_NEWLIB) || defined(MODULE_PICOLIBC)
|
#if !defined(__MSP430__)
|
||||||
/* no fflush on msp430 */
|
/* no fflush on msp430 */
|
||||||
fflush(stdout);
|
fflush(stdout);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef __cplusplus
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
/**@}*/
|
/**@}*/
|
||||||
#endif /* LOG_MODULE_H */
|
|
18
sys/log_printfnoformat/Kconfig
Normal file
18
sys/log_printfnoformat/Kconfig
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
# Copyright (c) 2019 HAW Hamburg
|
||||||
|
#
|
||||||
|
# This file is subject to the terms and conditions of the GNU Lesser
|
||||||
|
# General Public License v2.1. See the file LICENSE in the top level
|
||||||
|
# directory for more details.
|
||||||
|
#
|
||||||
|
choice LOG
|
||||||
|
#the choice prompt is described in sys/Kconfig
|
||||||
|
|
||||||
|
config MODULE_LOG_PRINTFNOFORMAT
|
||||||
|
bool "log_printfnoformat: puts-based log"
|
||||||
|
select MODULE_LOG
|
||||||
|
help
|
||||||
|
Logging is implemented using puts instead of printf. Use it where printf
|
||||||
|
might be too heavy. This also serves as an example for logging
|
||||||
|
implementation.
|
||||||
|
|
||||||
|
endchoice
|
1
sys/log_printfnoformat/Makefile
Normal file
1
sys/log_printfnoformat/Makefile
Normal file
@ -0,0 +1 @@
|
|||||||
|
include $(RIOTBASE)/Makefile.base
|
1
sys/log_printfnoformat/Makefile.include
Normal file
1
sys/log_printfnoformat/Makefile.include
Normal file
@ -0,0 +1 @@
|
|||||||
|
USEMODULE_INCLUDES += $(RIOTBASE)/sys/log_printfnoformat/include
|
@ -7,9 +7,10 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @defgroup sys_log_printfnoformat puts log module
|
* @defgroup sys_log_printfnoformat log_printfnoformat: puts log module
|
||||||
* @ingroup sys
|
* @ingroup sys
|
||||||
* @brief This module implements an example logging module
|
* @brief This module implements an example logging module using puts to
|
||||||
|
* just print the format string saving on the number of libraries need
|
||||||
* @{
|
* @{
|
||||||
*
|
*
|
||||||
* @file
|
* @file
|
Loading…
Reference in New Issue
Block a user