Skip to content

Commit

Permalink
[linux] Print log with timestamp and thread id (#7299)
Browse files Browse the repository at this point in the history
  • Loading branch information
erjiaqing authored and pull[bot] committed Jul 26, 2021
1 parent 8bddcc7 commit 9b58a94
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions src/platform/Linux/Logging.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,11 @@

#include <platform/logging/LogV.h>

#include <stdio.h>
#include <cinttypes>
#include <cstdio>
#include <sys/time.h>
#include <sys/types.h>
#include <unistd.h>

namespace chip {
namespace DeviceLayer {
Expand All @@ -25,7 +29,14 @@ namespace Platform {
*/
void LogV(const char * module, uint8_t category, const char * msg, va_list v)
{
printf("CHIP:%s: ", module);
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);

printf("[%" PRIu64 ".%06" PRIu64 "][%ld] CHIP:%s: ", static_cast<uint64_t>(tv.tv_sec), static_cast<uint64_t>(tv.tv_usec),
static_cast<long>(gettid()), module);
vprintf(msg, v);
printf("\n");
fflush(stdout);
Expand Down

0 comments on commit 9b58a94

Please sign in to comment.