Skip to content

Commit 6303c74

Browse files
authored
Replace Stream with Print as the logging output (#949)
The logging begin() method used to receive a Stream object, but it was only used for output. As the Stream object implements the input part of a stream, and inherits the whole output capabilities from Print, replace the use of Stream with Print Left LOG_STREAM with stream in the name, as it's a macro that can be defined at compilation time to define where to log out to, so users might have this set in their makefiles
1 parent f8c5c0b commit 6303c74

File tree

1 file changed

+13
-13
lines changed

1 file changed

+13
-13
lines changed

src/AudioTools/AudioLogger.h

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
#include "AudioConfig.h"
44
#ifdef ARDUINO
5-
# include "Stream.h"
5+
# include "Print.h"
66
#endif
77
// Logging Implementation
88
#if USE_AUDIO_LOGGING
@@ -36,14 +36,14 @@ class AudioLogger {
3636
};
3737

3838
/// activate the logging
39-
void begin(Stream& out, LogLevel level=LOG_LEVEL) {
40-
this->log_stream_ptr = &out;
39+
void begin(Print& out, LogLevel level=LOG_LEVEL) {
40+
this->log_print_ptr = &out;
4141
this->log_level = level;
4242
}
4343

4444
/// checks if the logging is active
4545
bool isLogging(LogLevel level = Info){
46-
return log_stream_ptr!=nullptr && level >= log_level;
46+
return log_print_ptr!=nullptr && level >= log_level;
4747
}
4848

4949
AudioLogger &prefix(const char* file, int line, LogLevel current_level){
@@ -56,7 +56,7 @@ class AudioLogger {
5656
#if defined(IS_DESKTOP) || defined(IS_DESKTOP_WITH_TIME_ONLY)
5757
fprintf( stderr, "%s\n", print_buffer);
5858
#else
59-
log_stream_ptr->println(print_buffer);
59+
log_print_ptr->println(print_buffer);
6060
#endif
6161
print_buffer[0]=0;
6262
unlock();
@@ -80,7 +80,7 @@ class AudioLogger {
8080
}
8181

8282
protected:
83-
Stream *log_stream_ptr = &LOG_STREAM;
83+
Print *log_print_ptr = &LOG_STREAM;
8484
const char* TAG = "AudioTools";
8585
LogLevel log_level = LOG_LEVEL;
8686
char print_buffer[LOG_PRINTF_BUFFER_SIZE];
@@ -104,13 +104,13 @@ class AudioLogger {
104104
int printPrefix(const char* file, int line, LogLevel current_level) const {
105105
const char* file_name = strrchr(file, '/') ? strrchr(file, '/') + 1 : file;
106106
const char* level_code = levelName(current_level);
107-
int len = log_stream_ptr->print("[");
108-
len += log_stream_ptr->print(level_code);
109-
len += log_stream_ptr->print("] ");
110-
len += log_stream_ptr->print(file_name);
111-
len += log_stream_ptr->print(" : ");
112-
len += log_stream_ptr->print(line);
113-
len += log_stream_ptr->print(" - ");
107+
int len = log_print_ptr->print("[");
108+
len += log_print_ptr->print(level_code);
109+
len += log_print_ptr->print("] ");
110+
len += log_print_ptr->print(file_name);
111+
len += log_print_ptr->print(" : ");
112+
len += log_print_ptr->print(line);
113+
len += log_print_ptr->print(" - ");
114114
return len;
115115
}
116116

0 commit comments

Comments
 (0)