Skip to content

Commit

Permalink
db_bench -use_stderr_info_logger to print timestamp (#10435)
Browse files Browse the repository at this point in the history
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: facebook/rocksdb#10435

Test Plan: Run "db_bench -use_stderr_info_logger"

Reviewed By: riversand963

Differential Revision: D38258699

fbshipit-source-id: 3fee6eb1205127b923bc6a660f86bd2742519aec
  • Loading branch information
siying authored and facebook-github-bot committed Jul 29, 2022
1 parent 15da225 commit aec28eb
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions util/stderr_logger.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include <stdarg.h>
#include <stdio.h>

#include "port/sys_time.h"
#include "rocksdb/env.h"

namespace ROCKSDB_NAMESPACE {
Expand All @@ -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<int>(now_tv.tv_usec),
static_cast<long long unsigned int>(thread_id));

vfprintf(stderr, format, ap);
fprintf(stderr, "\n");
}
Expand Down

0 comments on commit aec28eb

Please sign in to comment.