Arduino VS1053
Loading...
Searching...
No Matches
VS1053Logger.h
1#pragma once
2
3#pragma once
4#include "Arduino.h"
5#include "VS1053Config.h"
6#include <stdarg.h>
7#include <stdio.h>
8#include <string.h>
9
10namespace arduino_vs1053 {
11
12enum VS1053LogLevel_t { VS1053Debug, VS1053Info, VS1053Warning, VS1053Error };
13
19public:
20 // global actual loggin level for application
21 VS1053LogLevel_t logLevel = VS1053Warning;
22
24 bool begin(VS1053LogLevel_t l, Print &out) {
25 p_out = &out;
26 logLevel = l;
27 return true;
28 }
29
31 void log(VS1053LogLevel_t level, const char *fmt...) {
32 if (logLevel <= level) { // AUDIOKIT_LOG_LEVEL = Debug
33 char log_buffer[200];
34 strcpy(log_buffer, VS1053_log_msg[level]);
35 strcat(log_buffer, ": ");
36 va_list arg;
37 va_start(arg, fmt);
38 vsprintf(log_buffer + 9, fmt, arg);
39 va_end(arg);
40 p_out->println(log_buffer);
41 }
42 }
43
44protected:
45 // Error level as string
46 const char *VS1053_log_msg[4] = {"Debug", "Info", "Warning", "Error"};
47 Print *p_out = &VS1053_LOG_PORT;
48};
49
50extern VS1053LoggerClass VS1053Logger;
51
52#define VS1053_LOGD(fmt, ...) VS1053Logger.log(VS1053Debug, fmt, ##__VA_ARGS__)
53#define VS1053_LOGI(fmt, ...) VS1053Logger.log(VS1053Info, fmt, ##__VA_ARGS__)
54#define VS1053_LOGW(fmt, ...) VS1053Logger.log(VS1053Warning, fmt, ##__VA_ARGS__)
55#define VS1053_LOGE(fmt, ...) VS1053Logger.log(VS1053Error, fmt, ##__VA_ARGS__)
56
57} // namespace arduino_vs1053
Logging class which supports multiple log levels.
Definition: VS1053Logger.h:18
bool begin(VS1053LogLevel_t l, Print &out)
start the logger
Definition: VS1053Logger.h:24
void log(VS1053LogLevel_t level, const char *fmt...)
Print log message.
Definition: VS1053Logger.h:31