Skip to content

Commit 51a80ca

Browse files
committed
MCU8MASS-2198 Add functions for taking in va_list in logging module
1 parent b34629e commit 51a80ca

File tree

2 files changed

+55
-164
lines changed

2 files changed

+55
-164
lines changed

src/log.cpp

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,13 +157,21 @@ void LogClass::errorf(const char* format, ...) {
157157
va_end(args);
158158
}
159159

160+
void LogClass::errorfv(const char* format, va_list args) {
161+
this->printf(LogLevel::ERROR, format, args);
162+
}
163+
160164
void LogClass::errorf(const __FlashStringHelper* format, ...) {
161165
va_list args;
162166
va_start(args, format);
163167
this->printf(LogLevel::ERROR, format, args);
164168
va_end(args);
165169
}
166170

171+
void LogClass::errorfv(const __FlashStringHelper* format, va_list args) {
172+
this->printf(LogLevel::ERROR, format, args);
173+
}
174+
167175
void LogClass::warn(const char str[]) { this->print(LogLevel::WARN, str); }
168176

169177
void LogClass::warn(const String str) {
@@ -181,13 +189,21 @@ void LogClass::warnf(const char* format, ...) {
181189
va_end(args);
182190
}
183191

192+
void LogClass::warnfv(const char* format, va_list args) {
193+
this->printf(LogLevel::WARN, format, args);
194+
}
195+
184196
void LogClass::warnf(const __FlashStringHelper* format, ...) {
185197
va_list args;
186198
va_start(args, format);
187199
this->printf(LogLevel::WARN, format, args);
188200
va_end(args);
189201
}
190202

203+
void LogClass::warnfv(const __FlashStringHelper* format, va_list args) {
204+
this->printf(LogLevel::WARN, format, args);
205+
}
206+
191207
void LogClass::info(const char str[]) { this->print(LogLevel::INFO, str); }
192208

193209
void LogClass::info(const String str) {
@@ -205,13 +221,21 @@ void LogClass::infof(const char* format, ...) {
205221
va_end(args);
206222
}
207223

224+
void LogClass::infofv(const char* format, va_list args) {
225+
this->printf(LogLevel::INFO, format, args);
226+
}
227+
208228
void LogClass::infof(const __FlashStringHelper* format, ...) {
209229
va_list args;
210230
va_start(args, format);
211231
this->printf(LogLevel::INFO, format, args);
212232
va_end(args);
213233
}
214234

235+
void LogClass::infofv(const __FlashStringHelper* format, va_list args) {
236+
this->printf(LogLevel::INFO, format, args);
237+
}
238+
215239
void LogClass::debug(const char str[]) { this->print(LogLevel::DEBUG, str); }
216240

217241
void LogClass::debug(const String str) {
@@ -229,13 +253,21 @@ void LogClass::debugf(const char* format, ...) {
229253
va_end(args);
230254
}
231255

256+
void LogClass::debugfv(const char* format, va_list args) {
257+
this->printf(LogLevel::DEBUG, format, args);
258+
}
259+
232260
void LogClass::debugf(const __FlashStringHelper* format, ...) {
233261
va_list args;
234262
va_start(args, format);
235263
this->printf(LogLevel::DEBUG, format, args);
236264
va_end(args);
237265
}
238266

267+
void LogClass::debugfv(const __FlashStringHelper* format, va_list args) {
268+
this->printf(LogLevel::DEBUG, format, args);
269+
}
270+
239271
void LogClass::raw(const char str[]) { this->print(LogLevel::NONE, str); }
240272

241273
void LogClass::raw(const String str) {
@@ -253,11 +285,19 @@ void LogClass::rawf(const char* format, ...) {
253285
va_end(args);
254286
}
255287

288+
void LogClass::rawfv(const char* format, va_list args) {
289+
this->printf(LogLevel::NONE, format, args);
290+
}
291+
256292
void LogClass::rawf(const __FlashStringHelper* format, ...) {
257293
va_list args;
258294
va_start(args, format);
259295
this->printf(LogLevel::NONE, format, args);
260296
va_end(args);
261297
}
262298

299+
void LogClass::rawfv(const __FlashStringHelper* format, va_list args) {
300+
this->printf(LogLevel::NONE, format, args);
301+
}
302+
263303
#pragma GCC diagnostic pop

src/log.h

Lines changed: 15 additions & 164 deletions
Original file line numberDiff line numberDiff line change
@@ -58,200 +58,51 @@ class LogClass {
5858
void end();
5959

6060
/**
61-
* @brief Outputs a string with the ERROR log level.
62-
*
63-
* @param str [in] String to output.
61+
* In the following level functions, we explicitly use the postfix of v to
62+
* specify that we pass on a va_list. In this way, the compiler is not
63+
* confused between calling e.g. infof with a va_list and calling infofv (as
64+
* we should if we're passing on a va_list).
6465
*/
65-
void error(const char str[]);
6666

67-
/**
68-
* @brief Outputs a string with the error log level.
69-
*
70-
* @param str [in] String to output.
71-
*/
67+
void error(const char str[]);
7268
void error(const String str);
73-
74-
/**
75-
* @brief Outputs a string with the error log level, where the string is
76-
* stored in program memory.
77-
*
78-
* @param str [in] String to output.
79-
*/
8069
void error(const __FlashStringHelper* str);
81-
82-
/**
83-
* @brief Outputs a string with the error log level and optional formatting.
84-
*
85-
* @param format [in] Format string.
86-
* @param ... [in] Arguments for formatting.
87-
*/
8870
void errorf(const char* format, ...);
89-
90-
/**
91-
* @brief Outputs a string with the error log level and optional formatting,
92-
* where the formatting is stored in program memory.
93-
*
94-
* @param format [in] Format string.
95-
* @param ... [in] Arguments for formatting.
96-
*/
71+
void errorfv(const char* format, va_list args);
9772
void errorf(const __FlashStringHelper* format, ...);
73+
void errorfv(const __FlashStringHelper* format, va_list args);
9874

99-
/**
100-
* @brief Outputs a string with the warning log level.
101-
*
102-
* @param str [in] String to output.
103-
*/
10475
void warn(const char str[]);
105-
106-
/**
107-
* @brief Outputs a string with the warning log level.
108-
*
109-
* @param str [in] String to output.
110-
*/
11176
void warn(const String str);
112-
113-
/**
114-
* @brief Outputs a string with the warning log level, where the string is
115-
* stored in program memory.
116-
*
117-
* @param str [in] String to output.
118-
*/
11977
void warn(const __FlashStringHelper* str);
120-
121-
/**
122-
* @brief Outputs a string with the warning log level and optional
123-
* formatting.
124-
*
125-
* @param format [in] Format string.
126-
* @param ... [in] Arguments for formatting.
127-
*/
12878
void warnf(const char* format, ...);
129-
130-
/**
131-
* @brief Outputs a string with the warning log level and optional
132-
* formatting, where the formatting is stored in program memory.
133-
*
134-
* @param format [in] Format string.
135-
* @param ... [in] Arguments for formatting.
136-
*/
79+
void warnfv(const char* format, va_list args);
13780
void warnf(const __FlashStringHelper* format, ...);
81+
void warnfv(const __FlashStringHelper* format, va_list args);
13882

139-
/**
140-
* @brief Outputs a string with the info log level.
141-
*
142-
* @param str [in] String to output.
143-
*/
14483
void info(const char str[]);
145-
146-
/**
147-
* @brief Outputs a string with the info log level.
148-
*
149-
* @param str [in] String to output.
150-
*/
15184
void info(const String str);
152-
153-
/**
154-
* @brief Outputs a string with the info log level, where the string is
155-
* stored in program memory.
156-
*
157-
* @param str [in] String to output.
158-
*/
15985
void info(const __FlashStringHelper* str);
160-
161-
/**
162-
* @brief Outputs a string with the info log level and optional formatting.
163-
*
164-
* @param format [in] Format string.
165-
* @param ... [in] Arguments for formatting.
166-
*/
16786
void infof(const char* format, ...);
168-
169-
/**
170-
* @brief Outputs a string with the info log level and optional formatting,
171-
* where the formatting is stored in program memory.
172-
*
173-
* @param format [in] Format string.
174-
* @param ... [in] Arguments for formatting.
175-
*/
87+
void infofv(const char* format, va_list args);
17688
void infof(const __FlashStringHelper* format, ...);
89+
void infofv(const __FlashStringHelper* format, va_list args);
17790

178-
/**
179-
* @brief Outputs a string with the debug log level.
180-
*
181-
* @param str [in] String to output.
182-
*/
18391
void debug(const char str[]);
184-
185-
/**
186-
* @brief Outputs a string with the debug log level.
187-
*
188-
* @param str [in] String to output.
189-
*/
19092
void debug(const String str);
191-
192-
/**
193-
* @brief Outputs a string with the debug log level, where the string is
194-
* stored in program memory.
195-
*
196-
* @param str [in] String to output.
197-
*/
19893
void debug(const __FlashStringHelper* str);
199-
200-
/**
201-
* @brief Outputs a string with the debug log level and optional formatting.
202-
*
203-
* @param format [in] Format string.
204-
* @param ... [in] Arguments for formatting.
205-
*/
20694
void debugf(const char* format, ...);
207-
208-
/**
209-
* @brief Outputs a string with the debug log level and optional formatting,
210-
* where the formatting is stored in program memory.
211-
*
212-
* @param format [in] Format string.
213-
* @param ... [in] Arguments for formatting.
214-
*/
95+
void debugfv(const char* format, va_list args);
21596
void debugf(const __FlashStringHelper* format, ...);
97+
void debugfv(const __FlashStringHelper* format, va_list args);
21698

217-
/**
218-
* @brief Outputs a string without log level..
219-
*
220-
* @param str [in] String to output.
221-
*/
22299
void raw(const char str[]);
223-
224-
/**
225-
* @brief Outputs a string without log level.
226-
*
227-
* @param str [in] String to output.
228-
*/
229100
void raw(const String str);
230-
231-
/**
232-
* @brief Outputs a string without log level, where the string is stored in
233-
* program memory.
234-
*
235-
* @param str [in] String to output.
236-
*/
237101
void raw(const __FlashStringHelper* str);
238-
239-
/**
240-
* @brief Outputs a string without log level and optional formatting.
241-
*
242-
* @param format [in] Format string.
243-
* @param ... [in] Arguments for formatting.
244-
*/
245102
void rawf(const char* format, ...);
246-
247-
/**
248-
* @brief Outputs a string without log level and optional formatting, where
249-
* the formatting is stored in program memory.
250-
*
251-
* @param format [in] Format string.
252-
* @param ... [in] Arguments for formatting.
253-
*/
103+
void rawfv(const char* format, va_list args);
254104
void rawf(const __FlashStringHelper* format, ...);
105+
void rawfv(const __FlashStringHelper* format, va_list args);
255106

256107
private:
257108
/**

0 commit comments

Comments
 (0)