MIP_SDK  v3.0.0
MicroStrain Communications Library for embedded systems
logging.h
Go to the documentation of this file.
1 #pragma once
2 
3 #include <stdint.h>
4 #include <stdarg.h>
5 
6 #ifdef __cplusplus
7 extern "C" {
8 #endif
9 
22 
26 typedef uint8_t microstrain_log_level;
27 #define MICROSTRAIN_LOG_LEVEL_OFF 0
28 #define MICROSTRAIN_LOG_LEVEL_FATAL 1
29 #define MICROSTRAIN_LOG_LEVEL_ERROR 2
30 #define MICROSTRAIN_LOG_LEVEL_WARN 3
31 #define MICROSTRAIN_LOG_LEVEL_INFO 4
32 #define MICROSTRAIN_LOG_LEVEL_DEBUG 5
33 #define MICROSTRAIN_LOG_LEVEL_TRACE 6
34 
35 typedef void (*microstrain_log_callback)(void* user, microstrain_log_level level, const char* fmt, va_list args);
43 
45 
49 
50 void microstrain_logging_log(microstrain_log_level level, const char* fmt, ...);
51 
60 #ifdef MICROSTRAIN_ENABLE_LOGGING
61 #define MICROSTRAIN_LOG_INIT(callback, level, user) microstrain_logging_init(callback, level, user)
62 #else
63 #define MICROSTRAIN_LOG_INIT(callback, level, user) (void)0
64 #endif
65 
71 #ifdef MICROSTRAIN_ENABLE_LOGGING
72 #define MICROSTRAIN_LOG_LOG(level, ...) microstrain_logging_log(level, __VA_ARGS__)
73 #else
74 #define MICROSTRAIN_LOG_LOG(level, ...) (void)0
75 #endif
76 
77 #ifndef MICROSTRAIN_LOGGING_MAX_LEVEL
78 #define MICROSTRAIN_LOGGING_MAX_LEVEL MICROSTRAIN_LOG_LEVEL_WARN
79 #endif
80 
88 #if MICROSTRAIN_LOGGING_MAX_LEVEL >= MICROSTRAIN_LOG_LEVEL_FATAL
89 #define MICROSTRAIN_LOG_FATAL(...) MICROSTRAIN_LOG_LOG(MICROSTRAIN_LOG_LEVEL_FATAL, __VA_ARGS__)
90 #else
91 #define MICROSTRAIN_LOG_FATAL(...) (void)0
92 #endif
93 
97 #if MICROSTRAIN_LOGGING_MAX_LEVEL >= MICROSTRAIN_LOG_LEVEL_ERROR
98 #define MICROSTRAIN_LOG_ERROR(...) MICROSTRAIN_LOG_LOG(MICROSTRAIN_LOG_LEVEL_ERROR, __VA_ARGS__)
99 #else
100 #define MICROSTRAIN_LOG_ERROR(...) (void)0
101 #endif
102 
106 #if MICROSTRAIN_LOGGING_MAX_LEVEL >= MICROSTRAIN_LOG_LEVEL_WARN
107 #define MICROSTRAIN_LOG_WARN(...) MICROSTRAIN_LOG_LOG(MICROSTRAIN_LOG_LEVEL_WARN, __VA_ARGS__)
108 #else
109 #define MICROSTRAIN_LOG_WARN(...) (void)0
110 #endif
111 
115 #if MICROSTRAIN_LOGGING_MAX_LEVEL >= MICROSTRAIN_LOG_LEVEL_INFO
116 #define MICROSTRAIN_LOG_INFO(...) MICROSTRAIN_LOG_LOG(MICROSTRAIN_LOG_LEVEL_INFO, __VA_ARGS__)
117 #else
118 #define MICROSTRAIN_LOG_INFO(...) (void)0
119 #endif
120 
124 #if MICROSTRAIN_LOGGING_MAX_LEVEL >= MICROSTRAIN_LOG_LEVEL_DEBUG
125 #define MICROSTRAIN_LOG_DEBUG(...) MICROSTRAIN_LOG_LOG(MICROSTRAIN_LOG_LEVEL_DEBUG, __VA_ARGS__)
126 #else
127 #define MICROSTRAIN_LOG_DEBUG(...) (void)0
128 #endif
129 
133 #if MICROSTRAIN_LOGGING_MAX_LEVEL >= MICROSTRAIN_LOG_LEVEL_TRACE
134 #define MICROSTRAIN_LOG_TRACE(...) MICROSTRAIN_LOG_LOG(MICROSTRAIN_LOG_LEVEL_TRACE, __VA_ARGS__)
135 #else
136 #define MICROSTRAIN_LOG_TRACE(...) (void)0
137 #endif
138 
142 
143 #ifdef __cplusplus
144 } // extern "C"
145 #endif
microstrain_logging_user_data
void * microstrain_logging_user_data(void)
Gets the currently active logging user data.
Definition: logging.c:59
microstrain_logging_log
void microstrain_logging_log(microstrain_log_level level, const char *fmt,...)
Internal log function called by logging macros. Call MICROSTRAIN_LOG_* macros instead of using this f...
Definition: logging.c:69
microstrain_log_level
uint8_t microstrain_log_level
Logging level enum.
Definition: logging.h:26
microstrain_log_callback
void(* microstrain_log_callback)(void *user, microstrain_log_level level, const char *fmt, va_list args)
Callback function typedef for custom logging behavior.
Definition: logging.h:42
microstrain_logging_level
microstrain_log_level microstrain_logging_level(void)
Gets the currently active logging level.
Definition: logging.c:49
microstrain_logging_init
void microstrain_logging_init(microstrain_log_callback callback, microstrain_log_level level, void *user)
Initializes the logger with a callback and user data. Call MICROSTRAIN_LOG_INIT instead of using this...
Definition: logging.c:27
microstrain_logging_callback
microstrain_log_callback microstrain_logging_callback(void)
Gets the currently active logging callback.
Definition: logging.c:39