@@ -35,6 +35,7 @@ static Stream * DEFAULT_OUTPUT_STREAM = &Serial;
3535Arduino_DebugUtils::Arduino_DebugUtils () {
3636 timestampOff ();
3737 newlineOn ();
38+ debugLabelOff ();
3839 setDebugLevel (DEFAULT_DEBUG_LEVEL);
3940 setDebugOutputStream (DEFAULT_OUTPUT_STREAM);
4041}
@@ -63,6 +64,14 @@ void Arduino_DebugUtils::newlineOff() {
6364 _newline_on = false ;
6465}
6566
67+ void Arduino_DebugUtils::debugLabelOn () {
68+ _print_debug_label = true ;
69+ }
70+
71+ void Arduino_DebugUtils::debugLabelOff () {
72+ _print_debug_label = false ;
73+ }
74+
6675void Arduino_DebugUtils::timestampOn () {
6776 _timestamp_on = true ;
6877}
@@ -76,6 +85,9 @@ void Arduino_DebugUtils::print(int const debug_level, const char * fmt, ...)
7685 if (!shouldPrint (debug_level))
7786 return ;
7887
88+ if (_print_debug_label)
89+ printDebugLabel (debug_level);
90+
7991 if (_timestamp_on)
8092 printTimestamp ();
8193
@@ -90,6 +102,9 @@ void Arduino_DebugUtils::print(int const debug_level, const __FlashStringHelper
90102 if (!shouldPrint (debug_level))
91103 return ;
92104
105+ if (_print_debug_label)
106+ printDebugLabel (debug_level);
107+
93108 if (_timestamp_on)
94109 printTimestamp ();
95110
@@ -136,6 +151,24 @@ void Arduino_DebugUtils::printTimestamp()
136151 _debug_output_stream->print (timestamp);
137152}
138153
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+
139172bool Arduino_DebugUtils::shouldPrint (int const debug_level) const
140173{
141174 return ((debug_level >= DBG_ERROR) && (debug_level <= DBG_VERBOSE) && (debug_level <= _debug_level));
0 commit comments