1 /* See Project CHIP LICENSE file for licensing information. */
3 #include <platform/logging/LogV.h>
5 #include <core/CHIPConfig.h>
6 #include <support/logging/Constants.h>
9 #include <logging/log.h>
10 #include <sys/cbprintf.h>
12 LOG_MODULE_REGISTER(chip, LOG_LEVEL_DBG);
15 namespace DeviceLayer {
18 * Called whenever a log message is emitted by chip.
20 * This function is intended be overridden by the application to, e.g.,
21 * schedule output of queued log entries.
23 void __attribute__((weak)) OnLogOutput(void) {}
25 } // namespace DeviceLayer
31 * CHIP log output function.
34 void LogV(const char * module, uint8_t category, const char * msg, va_list v)
36 char formattedMsg[CHIP_CONFIG_LOG_MESSAGE_MAX_SIZE];
38 snprintfcb(formattedMsg, sizeof(formattedMsg), "%u [%s]", k_uptime_get_32(), module);
40 // -2 to ensure at least one byte available for vsnprintf below.
41 formattedMsg[sizeof(formattedMsg) - 2] = 0;
43 size_t prefixLen = strlen(formattedMsg);
45 // Append the log message.
46 vsnprintfcb(formattedMsg + prefixLen, sizeof(formattedMsg) - prefixLen, msg, v);
48 // Invoke the Zephyr logging library to log the message.
50 // Unfortunately the Zephyr logging macros end up assigning uint16_t
51 // variables to uint16_t:10 fields, which triggers integer conversion
52 // warnings. And treating the Zephyr headers as system headers does not
53 // help, apparently. Just turn off that warning around this switch.
54 #pragma GCC diagnostic push
55 #pragma GCC diagnostic ignored "-Wconversion"
58 case kLogCategory_Error:
59 LOG_ERR("%s", log_strdup(formattedMsg));
61 case kLogCategory_Progress:
63 LOG_INF("%s", log_strdup(formattedMsg));
65 case kLogCategory_Detail:
66 LOG_DBG("%s", log_strdup(formattedMsg));
69 #pragma GCC diagnostic pop
71 // Let the application know that a log message has been emitted.
72 DeviceLayer::OnLogOutput();
75 } // namespace Platform
76 } // namespace Logging