Logo Pico-Framework A web-first embedded framework for C++
Loading...
Searching...
No Matches
Logger.h
Go to the documentation of this file.
1
25 #ifndef LOGGER_H
26 #define LOGGER_H
27 #pragma once
28
29 #include <cstdio>
30 #include <ctime>
31 #include <string>
33
42
50 class Logger {
51 public:
56 static void info(const char* msg);
57
62 static void warn(const char* msg);
63
68 static void error(const char* msg);
69
74 static void setMinLogLevel(LogLevel level);
75
80 static void enableFileLogging(const std::string& path);
81
87 static bool forEachLine(const std::function<void(const char* line)>& handler);
88
89
90 private:
92 static void log(LogLevel level, const char* msg);
93 static void getTimeString(char* buffer, size_t len);
94 static const char* levelToString(LogLevel level);
95
96 static inline std::string logPath = "";
97 static inline bool logToFile = false;
98 };
99
100 #endif // LOGGER_H
101
LogLevel
Severity levels for logging.
Definition Logger.h:37
@ LOG_ERROR
Errors (potentially requiring user action)
Definition Logger.h:40
@ LOG_INFO
Informational messages.
Definition Logger.h:38
@ LOG_WARN
Warnings (non-fatal)
Definition Logger.h:39
Abstract interface for file and directory storage backends.
Basic timestamped logger with optional SD file logging.
Definition Logger.h:50
static void getTimeString(char *buffer, size_t len)
Definition Logger.cpp:79
static bool forEachLine(const std::function< void(const char *line)> &handler)
Streams each line of the log file to the provided handler.
Definition Logger.cpp:102
static LogLevel minLevel
Definition Logger.h:91
static const char * levelToString(LogLevel level)
Definition Logger.cpp:87
static void info(const char *msg)
Log an informational message.
Definition Logger.cpp:23
static bool logToFile
Definition Logger.h:97
static void error(const char *msg)
Log an error message.
Definition Logger.cpp:35
static void setMinLogLevel(LogLevel level)
Set the minimum log level (filters lower levels).
Definition Logger.cpp:41
static void enableFileLogging(const std::string &path)
Enable writing logs to SD card via a storage manager.
Definition Logger.cpp:47
static void warn(const char *msg)
Log a warning message.
Definition Logger.cpp:29
static std::string logPath
Definition Logger.h:96
static void log(LogLevel level, const char *msg)
Definition Logger.cpp:54