Skip to content
This repository was archived by the owner on Dec 20, 2023. It is now read-only.

Commit 5e5f5c3

Browse files
committed
Add fileName and lineNumber in WeaveLog*
Help debug and identify spammy log
1 parent 18d4aef commit 5e5f5c3

2 files changed

Lines changed: 10 additions & 6 deletions

File tree

src/lib/support/logging/WeaveLogging.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -250,6 +250,10 @@ static LogMessageFunct gLogFunct = DefaultLogMessage;
250250
* category of the log message. The category
251251
* may be filtered in or out if
252252
* WEAVE_LOG_FILTERING was asserted.
253+
* @param[in] fileName A pointer to a C-formatted, null terminated
254+
* string containing the full path to a file
255+
* @param[in] line A integer expanded from a preprocessor macro
256+
* indicating the line number in a source file
253257
* @param[in] msg A pointer to a NULL-terminated C string with
254258
* C Standard Library-style format specifiers
255259
* containing the log message to be formatted and
@@ -258,7 +262,7 @@ static LogMessageFunct gLogFunct = DefaultLogMessage;
258262
* correspond to the format specifiers in @a msg.
259263
*
260264
*/
261-
NL_DLL_EXPORT __WEAVE_LOGGING_LINK_ATTRIBUTE void Log(uint8_t module, uint8_t category, const char *msg, ...)
265+
NL_DLL_EXPORT __WEAVE_LOGGING_LINK_ATTRIBUTE void Log(uint8_t module, uint8_t category, const char *fileName, int line, const char *msg, ...)
262266
{
263267
va_list ap;
264268
va_start(ap, msg);

src/lib/support/logging/WeaveLogging.h

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,7 @@ enum LogCategory
210210
*
211211
*/
212212
#ifndef WeaveLogError
213-
#define WeaveLogError(MOD, MSG, ...) nl::Weave::Logging::Log( nl::Weave::Logging::kLogModule_##MOD , nl::Weave::Logging::kLogCategory_Error, MSG, ## __VA_ARGS__)
213+
#define WeaveLogError(MOD, MSG, ...) nl::Weave::Logging::Log( nl::Weave::Logging::kLogModule_##MOD , nl::Weave::Logging::kLogCategory_Error, __FILE__, __LINE__, MSG, ## __VA_ARGS__)
214214
#endif
215215
#else
216216
#define WeaveLogError(MOD, MSG, ...)
@@ -230,7 +230,7 @@ enum LogCategory
230230
*
231231
*/
232232
#ifndef WeaveLogProgress
233-
#define WeaveLogProgress(MOD, MSG, ...) nl::Weave::Logging::Log( nl::Weave::Logging::kLogModule_##MOD , nl::Weave::Logging::kLogCategory_Progress, MSG, ## __VA_ARGS__)
233+
#define WeaveLogProgress(MOD, MSG, ...) nl::Weave::Logging::Log( nl::Weave::Logging::kLogModule_##MOD , nl::Weave::Logging::kLogCategory_Progress, __FILE__, __LINE__, MSG, ## __VA_ARGS__)
234234
#endif
235235
#else
236236
#define WeaveLogProgress(MOD, MSG, ...)
@@ -251,7 +251,7 @@ enum LogCategory
251251
*
252252
*/
253253
#ifndef WeaveLogDetail
254-
#define WeaveLogDetail(MOD, MSG, ...) nl::Weave::Logging::Log( nl::Weave::Logging::kLogModule_##MOD , nl::Weave::Logging::kLogCategory_Detail, MSG, ## __VA_ARGS__)
254+
#define WeaveLogDetail(MOD, MSG, ...) nl::Weave::Logging::Log( nl::Weave::Logging::kLogModule_##MOD , nl::Weave::Logging::kLogCategory_Detail, __FILE__, __LINE__, MSG, ## __VA_ARGS__)
255255
#endif
256256
#else
257257
#define WeaveLogDetail(MOD, MSG, ...)
@@ -273,7 +273,7 @@ enum LogCategory
273273
*
274274
*/
275275
#ifndef WeaveLogRetain
276-
#define WeaveLogRetain(MOD, MSG, ...) nl::Weave::Logging::Log( nl::Weave::Logging::kLogModule_##MOD , nl::Weave::Logging::kLogCategory_Retain, MSG, ## __VA_ARGS__)
276+
#define WeaveLogRetain(MOD, MSG, ...) nl::Weave::Logging::Log( nl::Weave::Logging::kLogModule_##MOD , nl::Weave::Logging::kLogCategory_Retain, __FILE__, __LINE__, MSG, ## __VA_ARGS__)
277277
#endif
278278

279279
#else // #if WEAVE_RETAIN_LOGGING
@@ -308,7 +308,7 @@ extern void GetMessageWithPrefix(char *buf, uint8_t bufSize, uint8_t module, con
308308
extern void GetModuleName(char *buf, uint8_t module);
309309
extern void GetCategoryName(char *buf, uint8_t bufSize, uint8_t category);
310310
extern void PrintMessagePrefix(uint8_t module);
311-
extern void Log(uint8_t module, uint8_t category, const char *msg, ...);
311+
extern void Log(uint8_t module, uint8_t category, const char *fileName, int lineNumber, const char *msg, ...);
312312
extern uint8_t GetLogFilter(void);
313313
extern void SetLogFilter(uint8_t category);
314314

0 commit comments

Comments
 (0)