From aec28ebae60401987bc59acd212ca33597020204 Mon Sep 17 00:00:00 2001 From: sdong Date: Fri, 29 Jul 2022 11:24:52 -0700 Subject: [PATCH] db_bench -use_stderr_info_logger to print timestamp (#10435) Summary: Right now db_bench -use_stderr_info_logger would redirect RocksDB info logging to stderr but no timetamp is printed out. Add timestamp to there. Pull Request resolved: https://github.com/facebook/rocksdb/pull/10435 Test Plan: Run "db_bench -use_stderr_info_logger" Reviewed By: riversand963 Differential Revision: D38258699 fbshipit-source-id: 3fee6eb1205127b923bc6a660f86bd2742519aec --- util/stderr_logger.h | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/util/stderr_logger.h b/util/stderr_logger.h index abf8f5701..97bd62561 100644 --- a/util/stderr_logger.h +++ b/util/stderr_logger.h @@ -8,6 +8,7 @@ #include #include +#include "port/sys_time.h" #include "rocksdb/env.h" namespace ROCKSDB_NAMESPACE { @@ -23,6 +24,18 @@ class StderrLogger : public Logger { using Logger::Logv; virtual void Logv(const char* format, va_list ap) override { + const uint64_t thread_id = Env::Default()->GetThreadID(); + + port::TimeVal now_tv; + port::GetTimeOfDay(&now_tv, nullptr); + const time_t seconds = now_tv.tv_sec; + struct tm t; + port::LocalTimeR(&seconds, &t); + fprintf(stderr, "%04d/%02d/%02d-%02d:%02d:%02d.%06d %llx ", + t.tm_year + 1900, t.tm_mon + 1, t.tm_mday, t.tm_hour, t.tm_min, + t.tm_sec, static_cast(now_tv.tv_usec), + static_cast(thread_id)); + vfprintf(stderr, format, ap); fprintf(stderr, "\n"); }