Created
February 1, 2026 11:16
-
-
Save mutkuensert/7ff6f4b5a387f452ad27b7c2bc45e4c8 to your computer and use it in GitHub Desktop.
A Logging utility for Arduino projects
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #include "Log.h" | |
| void logf(const char* func, int line, const char* fmt, ...) { | |
| Serial.print("["); | |
| Serial.print(func); | |
| Serial.print(":"); | |
| Serial.print(line); | |
| Serial.print("] "); | |
| char buffer[128]; | |
| va_list args; | |
| va_start(args, fmt); | |
| vsnprintf(buffer, sizeof(buffer), fmt, args); | |
| va_end(args); | |
| Serial.println(buffer); | |
| } | |
| void logfln(const char* func, int line, const char* fmt, ...) { | |
| char buffer[128]; | |
| va_list args; | |
| va_start(args, fmt); | |
| vsnprintf(buffer, sizeof(buffer), fmt, args); | |
| va_end(args); | |
| Serial.print("["); | |
| Serial.print(func); | |
| Serial.print(":"); | |
| Serial.print(line); | |
| Serial.print("] "); | |
| Serial.println(buffer); | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #define FLAG_SHOW_METHOD_REFS true | |
| #if FLAG_SHOW_METHOD_REFS | |
| #define Log(msg) Serial.print("["); Serial.print(__PRETTY_FUNCTION__); Serial.print(":"); Serial.print(__LINE__); Serial.print("] "); Serial.print(msg) | |
| #else | |
| #define Log(msg) Serial.print(msg) | |
| #endif | |
| #if FLAG_SHOW_METHOD_REFS | |
| #define Logf(fmt, ...) logf(__PRETTY_FUNCTION__,__LINE__, fmt, ##__VA_ARGS__) | |
| #else | |
| #define Logf(fmt, ...) Serial.printf(fmt, ##__VA_ARGS__) | |
| #endif | |
| #if FLAG_SHOW_METHOD_REFS | |
| #define Logln(msg) Serial.print("["); Serial.print(__PRETTY_FUNCTION__); Serial.print(":"); Serial.print(__LINE__); Serial.print("] "); Serial.println(msg) | |
| #else | |
| #define Logln(msg) Serial.println(msg) | |
| #endif | |
| #if FLAG_SHOW_METHOD_REFS | |
| #define Logfln(fmt, ...) logfln(__PRETTY_FUNCTION__,__LINE__, fmt, ##__VA_ARGS__) | |
| #else | |
| #define Logfln(fmt, ...) Serial.printf(fmt, ##__VA_ARGS__); Serial.println("") | |
| #endif | |
| #define LogPlain(msg) Serial.print(msg) | |
| #define LogPlainLn(msg) Serial.println(msg) | |
| #include <Arduino.h> | |
| #include <stdarg.h> | |
| void logf(const char* tag, int level, const char* fmt, ...); | |
| void logfln(const char* tag, int level, const char* fmt, ...); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment