Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[linux] Print log with timestamp and thread id #7299

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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),
erjiaqing marked this conversation as resolved.
Show resolved Hide resolved
static_cast<long>(gettid()), module);
vprintf(msg, v);
printf("\n");
fflush(stdout);
Expand Down