Solaris Software
Toggle main menu visibility
Loading...
Searching...
No Matches
log.h
Go to the documentation of this file.
1
/**
2
* @file log.h
3
* @brief SPP logging service.
4
*
5
* Usage:
6
* SPP_LOGI("MY_MODULE", "sensor value = %.2f", value);
7
*
8
* Each macro formats the message and calls the active output function.
9
* By default that function prints to stdout. SPP_CORE_boot() replaces
10
* it with one that also publishes each message as a pub/sub packet so
11
* subscribers (e.g. the SD card logger) receive log lines automatically.
12
*
13
* To silence everything: SPP_SERVICES_LOG_setLevel(K_SPP_LOG_NONE)
14
* To change destination: SPP_SERVICES_LOG_setOutput(myFn)
15
*/
16
17
#ifndef SPP_LOG_H
18
#define SPP_LOG_H
19
20
#include "
spp/core/types.h
"
21
#include "
spp/core/returnTypes.h
"
22
23
/* ----------------------------------------------------------------
24
* Log levels (higher value = more output)
25
* ---------------------------------------------------------------- */
26
27
typedef
enum
28
{
29
K_SPP_LOG_NONE
= 0,
/* Silence everything */
30
K_SPP_LOG_ERROR
= 1,
/* Errors only */
31
K_SPP_LOG_WARN
= 2,
/* Errors + warnings */
32
K_SPP_LOG_INFO
= 3,
/* Normal operational output */
33
K_SPP_LOG_DEBUG
= 4,
/* Extra detail */
34
K_SPP_LOG_VERBOSE
= 5
/* Everything */
35
}
SPP_LogLevel_t
;
36
37
/* ----------------------------------------------------------------
38
* Output function type
39
*
40
* A function that receives a fully-formatted log message and does
41
* something with it (print it, write it to SD, publish it, …).
42
* ---------------------------------------------------------------- */
43
44
typedef
void (*
SPP_LogOutputFn_t
)(
const
char
*p_tag,
SPP_LogLevel_t
level,
45
const
char
*p_message);
46
47
/* ----------------------------------------------------------------
48
* API
49
* ---------------------------------------------------------------- */
50
51
SPP_RetVal_t
SPP_SERVICES_LOG_init
(
void
);
52
53
void
SPP_SERVICES_LOG_setLevel
(
SPP_LogLevel_t
level);
54
SPP_LogLevel_t
SPP_SERVICES_LOG_getLevel
(
void
);
55
56
/* Replace the active output function. Pass NULL to silence all output. */
57
void
SPP_SERVICES_LOG_setOutput
(
SPP_LogOutputFn_t
p_fn);
58
59
/* Internal — called by the macros below, do not call directly. */
60
void
SPP_SERVICES_LOG_emit
(
const
char
*p_tag,
SPP_LogLevel_t
level,
61
const
char
*p_fmt, ...);
62
63
/* ----------------------------------------------------------------
64
* Macros — use these everywhere
65
* ---------------------------------------------------------------- */
66
67
#define SPP_LOGE(tag, fmt, ...) SPP_SERVICES_LOG_emit((tag), K_SPP_LOG_ERROR, (fmt), ##__VA_ARGS__)
68
#define SPP_LOGW(tag, fmt, ...) SPP_SERVICES_LOG_emit((tag), K_SPP_LOG_WARN, (fmt), ##__VA_ARGS__)
69
#define SPP_LOGI(tag, fmt, ...) SPP_SERVICES_LOG_emit((tag), K_SPP_LOG_INFO, (fmt), ##__VA_ARGS__)
70
#define SPP_LOGD(tag, fmt, ...) SPP_SERVICES_LOG_emit((tag), K_SPP_LOG_DEBUG, (fmt), ##__VA_ARGS__)
71
#define SPP_LOGV(tag, fmt, ...) SPP_SERVICES_LOG_emit((tag), K_SPP_LOG_VERBOSE, (fmt), ##__VA_ARGS__)
72
73
#endif
/* SPP_LOG_H */
SPP_SERVICES_LOG_emit
void SPP_SERVICES_LOG_emit(const char *p_tag, SPP_LogLevel_t level, const char *p_fmt,...)
Definition
log.c:42
SPP_SERVICES_LOG_setOutput
void SPP_SERVICES_LOG_setOutput(SPP_LogOutputFn_t p_fn)
Definition
log.c:37
SPP_SERVICES_LOG_init
SPP_RetVal_t SPP_SERVICES_LOG_init(void)
Definition
log.c:20
SPP_SERVICES_LOG_getLevel
SPP_LogLevel_t SPP_SERVICES_LOG_getLevel(void)
Definition
log.c:32
SPP_SERVICES_LOG_setLevel
void SPP_SERVICES_LOG_setLevel(SPP_LogLevel_t level)
Definition
log.c:27
SPP_LogOutputFn_t
void(*) SPP_LogOutputFn_t(const char *p_tag, SPP_LogLevel_t level, const char *p_message)
Definition
log.h:44
SPP_LogLevel_t
SPP_LogLevel_t
Definition
log.h:28
K_SPP_LOG_INFO
@ K_SPP_LOG_INFO
Definition
log.h:32
K_SPP_LOG_WARN
@ K_SPP_LOG_WARN
Definition
log.h:31
K_SPP_LOG_DEBUG
@ K_SPP_LOG_DEBUG
Definition
log.h:33
K_SPP_LOG_ERROR
@ K_SPP_LOG_ERROR
Definition
log.h:30
K_SPP_LOG_NONE
@ K_SPP_LOG_NONE
Definition
log.h:29
K_SPP_LOG_VERBOSE
@ K_SPP_LOG_VERBOSE
Definition
log.h:34
returnTypes.h
Standard return-value type used across all SPP modules.
SPP_RetVal_t
SPP_RetVal_t
Unified return type for all SPP API functions.
Definition
returnTypes.h:24
types.h
Portable integer types and SPI/storage configuration types for SPP.
solaris-v2
spp
services
log
log.h
Generated by
1.18.0