2016-04-01 18:06:06 +00:00
|
|
|
// Copyright (c) 2016-present, Facebook, Inc. All rights reserved.
|
2017-07-15 23:03:42 +00:00
|
|
|
// This source code is licensed under both the GPLv2 (found in the
|
|
|
|
// COPYING file in the root directory) and Apache 2.0 License
|
|
|
|
// (found in the LICENSE.Apache file in the root directory).
|
2016-04-01 18:06:06 +00:00
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <stdarg.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
|
2022-07-29 18:24:52 +00:00
|
|
|
#include "port/sys_time.h"
|
2016-04-01 18:06:06 +00:00
|
|
|
#include "rocksdb/env.h"
|
|
|
|
|
2020-02-20 20:07:53 +00:00
|
|
|
namespace ROCKSDB_NAMESPACE {
|
2016-04-01 18:06:06 +00:00
|
|
|
|
|
|
|
// Prints logs to stderr for faster debugging
|
|
|
|
class StderrLogger : public Logger {
|
|
|
|
public:
|
|
|
|
explicit StderrLogger(const InfoLogLevel log_level = InfoLogLevel::INFO_LEVEL)
|
|
|
|
: Logger(log_level) {}
|
|
|
|
|
|
|
|
// Brings overloaded Logv()s into scope so they're not hidden when we override
|
|
|
|
// a subset of them.
|
|
|
|
using Logger::Logv;
|
|
|
|
|
|
|
|
virtual void Logv(const char* format, va_list ap) override {
|
2022-07-29 18:24:52 +00:00
|
|
|
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));
|
|
|
|
|
2016-04-01 18:06:06 +00:00
|
|
|
vfprintf(stderr, format, ap);
|
|
|
|
fprintf(stderr, "\n");
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2020-02-20 20:07:53 +00:00
|
|
|
} // namespace ROCKSDB_NAMESPACE
|