Arduino LibHelix

helix_log.h
1 #pragma once
2
3 // User Settings: Activate/Deactivate logging
4 #if ! defined(HELIX_LOGGING_ACTIVE) && defined(ARDUINO)
5 #define HELIX_LOGGING_ACTIVE true
6 #endif
7
8 #ifndef HELIX_LOG_LEVEL
9 #define HELIX_LOG_LEVEL Warning
10 #endif
11
12 #ifndef HELIX_LOGGING_OUT
13 #define HELIX_LOGGING_OUT Serial
14 #endif
15
16 // Logging Implementation
17 #if HELIX_LOGGING_ACTIVE == true
18 static char log_buffer_helix[512];
19 enum LogLevelHelix {Debug, Info, Warning, Error};
20 static LogLevelHelix minLogLevelHelix = HELIX_LOG_LEVEL;
21 // We print the log based on the log level
22 #define LOG_HELIX(level,...) { if(level>=minLogLevelHelix) { int l = snprintf(log_buffer_helix,512, __VA_ARGS__); HELIX_LOGGING_OUT.print("libhelix - "); HELIX_LOGGING_OUT.write(log_buffer_helix,l); HELIX_LOGGING_OUT.println(); } }
23 #else
24 // Remove all log statments from the code
25 #define LOG_HELIX(...)
26 #endif