Arduino TinyFTP
All Classes Functions Pages
FTPLogger.h
1 #pragma once
2 
3 #include "FTPCommon.h"
4 
5 namespace ftp_client {
6 
7 // initialize static variables
8 static LogLevel ftp_min_log_level = LOG_ERROR;
9 static Stream *ftp_logger_out_ptr = nullptr;
10 
17 class FTPLogger {
18  public:
19  static void setLogLevel(LogLevel level) {
20  ftp_min_log_level = level;
21  }
22 
23  static LogLevel getLogLevel() {
24  return ftp_min_log_level;
25  }
26 
27  static void setOutput(Stream &out) {
28  ftp_logger_out_ptr = &out;
29  }
30 
31  static void writeLog(LogLevel level, const char *module, const char *msg = nullptr) {
32  if (ftp_logger_out_ptr != nullptr && level >= ftp_min_log_level) {
33  ftp_logger_out_ptr->print("FTP ");
34  switch (level) {
35  case LOG_DEBUG:
36  ftp_logger_out_ptr->print("DEBUG - ");
37  break;
38  case LOG_INFO:
39  ftp_logger_out_ptr->print("INFO - ");
40  break;
41  case LOG_WARN:
42  ftp_logger_out_ptr->print("WARN - ");
43  break;
44  case LOG_ERROR:
45  ftp_logger_out_ptr->print("ERROR - ");
46  break;
47  }
48  ftp_logger_out_ptr->print(module);
49  if (msg != nullptr) {
50  ftp_logger_out_ptr->print(": ");
51  ftp_logger_out_ptr->print(msg);
52  }
53  ftp_logger_out_ptr->println();
54  }
55  }
56 };
57 
58 }
FTPLogger To activate logging define the output stream e.g. with FTPLogger.setOutput(Serial); and (op...
Definition: FTPLogger.h:17