@@ -60,36 +60,32 @@ void Arduino_DebugUtils::timestampOff() {
6060
6161void Arduino_DebugUtils::print (int const debug_level, const char * fmt, ...)
6262{
63- if (debug_level >= DBG_ERROR &&
64- debug_level <= DBG_VERBOSE &&
65- debug_level <= _debug_level)
66- {
67- if (_timestamp_on)
68- printTimestamp ();
69-
70- va_list args;
71- va_start (args, fmt);
72- vPrint (fmt, args);
73- va_end (args);
74- }
63+ if (!shouldPrint (debug_level))
64+ return ;
65+
66+ if (_timestamp_on)
67+ printTimestamp ();
68+
69+ va_list args;
70+ va_start (args, fmt);
71+ vPrint (fmt, args);
72+ va_end (args);
7573}
7674
7775void Arduino_DebugUtils::print (int const debug_level, const __FlashStringHelper * fmt, ...)
7876{
79- if (debug_level >= DBG_ERROR &&
80- debug_level <= DBG_VERBOSE &&
81- debug_level <= _debug_level)
82- {
83- if (_timestamp_on)
84- printTimestamp ();
85-
86- String fmt_str (fmt);
87-
88- va_list args;
89- va_start (args, fmt_str.c_str ());
90- vPrint (fmt_str.c_str (), args);
91- va_end (args);
92- }
77+ if (!shouldPrint (debug_level))
78+ return ;
79+
80+ if (_timestamp_on)
81+ printTimestamp ();
82+
83+ String fmt_str (fmt);
84+
85+ va_list args;
86+ va_start (args, fmt_str.c_str ());
87+ vPrint (fmt_str.c_str (), args);
88+ va_end (args);
9389}
9490
9591/* *****************************************************************************
@@ -112,6 +108,11 @@ void Arduino_DebugUtils::printTimestamp()
112108 _debug_output_stream->print (timestamp);
113109}
114110
111+ bool Arduino_DebugUtils::shouldPrint (int const debug_level) const
112+ {
113+ return ((debug_level >= DBG_ERROR) && (debug_level <= DBG_VERBOSE) && (debug_level <= _debug_level));
114+ }
115+
115116/* *****************************************************************************
116117 CLASS INSTANTIATION
117118 ******************************************************************************/
0 commit comments