From 5e5f5c3fbe8cb35dc53c5d3fc0db25bd2dadd4a8 Mon Sep 17 00:00:00 2001 From: Didi She Date: Wed, 13 Jan 2021 19:19:34 -0800 Subject: [PATCH] Add fileName and lineNumber in WeaveLog* Help debug and identify spammy log --- src/lib/support/logging/WeaveLogging.cpp | 6 +++++- src/lib/support/logging/WeaveLogging.h | 10 +++++----- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/src/lib/support/logging/WeaveLogging.cpp b/src/lib/support/logging/WeaveLogging.cpp index 5325371423..4dd04c5e4a 100644 --- a/src/lib/support/logging/WeaveLogging.cpp +++ b/src/lib/support/logging/WeaveLogging.cpp @@ -250,6 +250,10 @@ static LogMessageFunct gLogFunct = DefaultLogMessage; * category of the log message. The category * may be filtered in or out if * WEAVE_LOG_FILTERING was asserted. + * @param[in] fileName A pointer to a C-formatted, null terminated + * string containing the full path to a file + * @param[in] line A integer expanded from a preprocessor macro + * indicating the line number in a source file * @param[in] msg A pointer to a NULL-terminated C string with * C Standard Library-style format specifiers * containing the log message to be formatted and @@ -258,7 +262,7 @@ static LogMessageFunct gLogFunct = DefaultLogMessage; * correspond to the format specifiers in @a msg. * */ -NL_DLL_EXPORT __WEAVE_LOGGING_LINK_ATTRIBUTE void Log(uint8_t module, uint8_t category, const char *msg, ...) +NL_DLL_EXPORT __WEAVE_LOGGING_LINK_ATTRIBUTE void Log(uint8_t module, uint8_t category, const char *fileName, int line, const char *msg, ...) { va_list ap; va_start(ap, msg); diff --git a/src/lib/support/logging/WeaveLogging.h b/src/lib/support/logging/WeaveLogging.h index 593a4a2db3..5766a463cc 100644 --- a/src/lib/support/logging/WeaveLogging.h +++ b/src/lib/support/logging/WeaveLogging.h @@ -210,7 +210,7 @@ enum LogCategory * */ #ifndef WeaveLogError -#define WeaveLogError(MOD, MSG, ...) nl::Weave::Logging::Log( nl::Weave::Logging::kLogModule_##MOD , nl::Weave::Logging::kLogCategory_Error, MSG, ## __VA_ARGS__) +#define WeaveLogError(MOD, MSG, ...) nl::Weave::Logging::Log( nl::Weave::Logging::kLogModule_##MOD , nl::Weave::Logging::kLogCategory_Error, __FILE__, __LINE__, MSG, ## __VA_ARGS__) #endif #else #define WeaveLogError(MOD, MSG, ...) @@ -230,7 +230,7 @@ enum LogCategory * */ #ifndef WeaveLogProgress -#define WeaveLogProgress(MOD, MSG, ...) nl::Weave::Logging::Log( nl::Weave::Logging::kLogModule_##MOD , nl::Weave::Logging::kLogCategory_Progress, MSG, ## __VA_ARGS__) +#define WeaveLogProgress(MOD, MSG, ...) nl::Weave::Logging::Log( nl::Weave::Logging::kLogModule_##MOD , nl::Weave::Logging::kLogCategory_Progress, __FILE__, __LINE__, MSG, ## __VA_ARGS__) #endif #else #define WeaveLogProgress(MOD, MSG, ...) @@ -251,7 +251,7 @@ enum LogCategory * */ #ifndef WeaveLogDetail -#define WeaveLogDetail(MOD, MSG, ...) nl::Weave::Logging::Log( nl::Weave::Logging::kLogModule_##MOD , nl::Weave::Logging::kLogCategory_Detail, MSG, ## __VA_ARGS__) +#define WeaveLogDetail(MOD, MSG, ...) nl::Weave::Logging::Log( nl::Weave::Logging::kLogModule_##MOD , nl::Weave::Logging::kLogCategory_Detail, __FILE__, __LINE__, MSG, ## __VA_ARGS__) #endif #else #define WeaveLogDetail(MOD, MSG, ...) @@ -273,7 +273,7 @@ enum LogCategory * */ #ifndef WeaveLogRetain -#define WeaveLogRetain(MOD, MSG, ...) nl::Weave::Logging::Log( nl::Weave::Logging::kLogModule_##MOD , nl::Weave::Logging::kLogCategory_Retain, MSG, ## __VA_ARGS__) +#define WeaveLogRetain(MOD, MSG, ...) nl::Weave::Logging::Log( nl::Weave::Logging::kLogModule_##MOD , nl::Weave::Logging::kLogCategory_Retain, __FILE__, __LINE__, MSG, ## __VA_ARGS__) #endif #else // #if WEAVE_RETAIN_LOGGING @@ -308,7 +308,7 @@ extern void GetMessageWithPrefix(char *buf, uint8_t bufSize, uint8_t module, con extern void GetModuleName(char *buf, uint8_t module); extern void GetCategoryName(char *buf, uint8_t bufSize, uint8_t category); extern void PrintMessagePrefix(uint8_t module); -extern void Log(uint8_t module, uint8_t category, const char *msg, ...); +extern void Log(uint8_t module, uint8_t category, const char *fileName, int lineNumber, const char *msg, ...); extern uint8_t GetLogFilter(void); extern void SetLogFilter(uint8_t category);