forked from project-chip/connectedhomeip
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathLogging.cpp
60 lines (47 loc) · 1.5 KB
/
Logging.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
/* See Project CHIP LICENSE file for licensing information. */
#include <platform/logging/LogV.h>
#include <cinttypes>
#include <cstdio>
#include <sys/syscall.h>
#include <sys/time.h>
#include <unistd.h>
#include <lib/support/logging/Constants.h>
#ifdef USE_SYSLOG
#include <syslog.h>
#endif
namespace chip {
namespace DeviceLayer {
/**
* Called whenever a log message is emitted by chip or LwIP.
*
* This function is intended be overridden by the application to, e.g.,
* schedule output of queued log entries.
*/
void __attribute__((weak)) OnLogOutput() {}
} // namespace DeviceLayer
namespace Logging {
namespace Platform {
/**
* CHIP log output functions.
*/
void LogV(const char * module, uint8_t category, const char * msg, va_list v)
{
struct timeval tv;
// Should not fail per man page of gettimeofday(), but failed to get time is not a fatal error in log. The bad time value will
// indicate the error occurred during getting time.
gettimeofday(&tv, nullptr);
#ifdef USE_SYSLOG
vsyslog(category, msg, v);
#else
printf("[%" PRIu64 ".%06" PRIu64 "][%lld:%lld] CHIP:%s: ", static_cast<uint64_t>(tv.tv_sec), static_cast<uint64_t>(tv.tv_usec),
static_cast<long long>(syscall(SYS_getpid)), static_cast<long long>(syscall(SYS_gettid)), module);
vprintf(msg, v);
printf("\n");
fflush(stdout);
#endif
// Let the application know that a log message has been emitted.
DeviceLayer::OnLogOutput();
}
} // namespace Platform
} // namespace Logging
} // namespace chip