Skip to content

Commit

Permalink
Add a timestamp + thread id to Darwin logging (#6354)
Browse files Browse the repository at this point in the history
  • Loading branch information
vivien-apple authored and pull[bot] committed Jul 30, 2021
1 parent c8d3d88 commit d747fbf
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion src/platform/Darwin/Logging.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,28 @@

#include <os/log.h>

#include <inttypes.h>
#include <pthread.h>
#include <stdarg.h>
#include <stdio.h>
#include <string.h>
#include <sys/time.h>

namespace chip {
namespace Logging {
namespace Platform {

void LogV(const char * module, uint8_t category, const char * msg, va_list v)
{
timeval time;
gettimeofday(&time, NULL);
long ms = (time.tv_sec * 1000) + (time.tv_usec / 1000);

uint64_t ktid;
pthread_threadid_np(NULL, &ktid);

char formattedMsg[CHIP_CONFIG_LOG_MESSAGE_MAX_SIZE];
int32_t prefixLen = snprintf(formattedMsg, sizeof(formattedMsg), "CHIP: [%s] ", module);
int32_t prefixLen = snprintf(formattedMsg, sizeof(formattedMsg), "[%ld] [0x%" PRIx64 "] CHIP: [%s] ", ms, ktid, module);
static os_log_t log = os_log_create("com.zigbee.chip", "all");
if (prefixLen < 0)
{
Expand Down

0 comments on commit d747fbf

Please sign in to comment.