@@ -35,6 +35,7 @@ static Stream * DEFAULT_OUTPUT_STREAM = &Serial;
35
35
Arduino_DebugUtils::Arduino_DebugUtils () {
36
36
timestampOff ();
37
37
newlineOn ();
38
+ debugLabelOff ();
38
39
setDebugLevel (DEFAULT_DEBUG_LEVEL);
39
40
setDebugOutputStream (DEFAULT_OUTPUT_STREAM);
40
41
}
@@ -63,6 +64,14 @@ void Arduino_DebugUtils::newlineOff() {
63
64
_newline_on = false ;
64
65
}
65
66
67
+ void Arduino_DebugUtils::debugLabelOn () {
68
+ _print_debug_label = true ;
69
+ }
70
+
71
+ void Arduino_DebugUtils::debugLabelOff () {
72
+ _print_debug_label = false ;
73
+ }
74
+
66
75
void Arduino_DebugUtils::timestampOn () {
67
76
_timestamp_on = true ;
68
77
}
@@ -76,6 +85,9 @@ void Arduino_DebugUtils::print(int const debug_level, const char * fmt, ...)
76
85
if (!shouldPrint (debug_level))
77
86
return ;
78
87
88
+ if (_print_debug_label)
89
+ printDebugLabel (debug_level);
90
+
79
91
if (_timestamp_on)
80
92
printTimestamp ();
81
93
@@ -90,6 +102,9 @@ void Arduino_DebugUtils::print(int const debug_level, const __FlashStringHelper
90
102
if (!shouldPrint (debug_level))
91
103
return ;
92
104
105
+ if (_print_debug_label)
106
+ printDebugLabel (debug_level);
107
+
93
108
if (_timestamp_on)
94
109
printTimestamp ();
95
110
@@ -136,6 +151,24 @@ void Arduino_DebugUtils::printTimestamp()
136
151
_debug_output_stream->print (timestamp);
137
152
}
138
153
154
+ void Arduino_DebugUtils::printDebugLabel (int const debug_level)
155
+ {
156
+ static char const * DEBUG_MODE_STRING[5 ] =
157
+ {
158
+ " [DBG_ERROR ] " ,
159
+ " [DBG_WARNING] " ,
160
+ " [DBG_INFO ] " ,
161
+ " [DBG_DEBUG ] " ,
162
+ " [DBG_VERBOSE] " ,
163
+ };
164
+
165
+ bool is_valid_debug_level = (debug_level >= DBG_ERROR) && (debug_level <= DBG_VERBOSE);
166
+ if (!is_valid_debug_level)
167
+ return ;
168
+
169
+ _debug_output_stream->print (DEBUG_MODE_STRING[debug_level]);
170
+ }
171
+
139
172
bool Arduino_DebugUtils::shouldPrint (int const debug_level) const
140
173
{
141
174
return ((debug_level >= DBG_ERROR) && (debug_level <= DBG_VERBOSE) && (debug_level <= _debug_level));
0 commit comments