Run clang format on logging folder (#10861)

Summary: Pull Request resolved: https://github.com/facebook/rocksdb/pull/10861

Test Plan: CircleCI jobs

Reviewed By: siying

Differential Revision: D40654198

Pulled By: akankshamahajan15

fbshipit-source-id: 787be2575578b3aa3bd985509f96fdb9e02f7ad7
main
akankshamahajan 2 years ago committed by Facebook GitHub Bot
parent ee3dbdc083
commit 935aae3bcf
  1. 4
      logging/auto_roll_logger.cc
  2. 8
      logging/auto_roll_logger.h
  3. 23
      logging/auto_roll_logger_test.cc
  4. 1
      logging/env_logger_test.cc
  5. 4
      logging/event_logger.cc
  6. 9
      logging/event_logger.h
  7. 3
      logging/event_logger_test.cc
  8. 5
      logging/log_buffer.cc
  9. 1
      logging/log_buffer.h
  10. 6
      logging/logging.h

@ -90,8 +90,8 @@ void AutoRollLogger::RollLogFile() {
uint64_t now = clock_->NowMicros(); uint64_t now = clock_->NowMicros();
std::string old_fname; std::string old_fname;
do { do {
old_fname = OldInfoLogFileName( old_fname =
dbname_, now, db_absolute_path_, db_log_dir_); OldInfoLogFileName(dbname_, now, db_absolute_path_, db_log_dir_);
now++; now++;
} while (fs_->FileExists(old_fname, io_options_, &io_context_).ok()); } while (fs_->FileExists(old_fname, io_options_, &io_context_).ok());
// Wait for logger_ reference count to turn to 1 as it might be pinned by // Wait for logger_ reference count to turn to 1 as it might be pinned by

@ -40,9 +40,7 @@ class AutoRollLogger : public Logger {
virtual void LogHeader(const char* format, va_list ap) override; virtual void LogHeader(const char* format, va_list ap) override;
// check if the logger has encountered any problem. // check if the logger has encountered any problem.
Status GetStatus() { Status GetStatus() { return status_; }
return status_;
}
size_t GetLogFileSize() const override { size_t GetLogFileSize() const override {
if (!logger_) { if (!logger_) {
@ -101,9 +99,7 @@ class AutoRollLogger : public Logger {
} }
// Expose the log file path for testing purpose // Expose the log file path for testing purpose
std::string TEST_log_fname() const { std::string TEST_log_fname() const { return log_fname_; }
return log_fname_;
}
uint64_t TEST_ctime() const { return ctime_; } uint64_t TEST_ctime() const { return ctime_; }

@ -64,8 +64,9 @@ class AutoRollLoggerTest : public testing::Test {
ASSERT_TRUE(system(deleteDbDirCmd.c_str()) == 0); ASSERT_TRUE(system(deleteDbDirCmd.c_str()) == 0);
std::string testDir(kTestDir); std::string testDir(kTestDir);
std::replace_if(testDir.begin(), testDir.end(), std::replace_if(
[](char ch) { return ch == '/'; }, '\\'); testDir.begin(), testDir.end(), [](char ch) { return ch == '/'; },
'\\');
std::string deleteCmd = "if exist " + testDir + " rd /s /q " + testDir; std::string deleteCmd = "if exist " + testDir + " rd /s /q " + testDir;
#else #else
std::string deleteCmd = "rm -rf " + kTestDir + " " + kTestDbDir; std::string deleteCmd = "rm -rf " + kTestDir + " " + kTestDbDir;
@ -207,8 +208,8 @@ TEST_F(AutoRollLoggerTest, RollLogFileBySize) {
size_t log_max_size = 1024 * 5; size_t log_max_size = 1024 * 5;
size_t keep_log_file_num = 10; size_t keep_log_file_num = 10;
AutoRollLogger logger(FileSystem::Default(), SystemClock::Default(), AutoRollLogger logger(FileSystem::Default(), SystemClock::Default(), kTestDir,
kTestDir, "", log_max_size, 0, keep_log_file_num); "", log_max_size, 0, keep_log_file_num);
RollLogFileBySizeTest(&logger, log_max_size, RollLogFileBySizeTest(&logger, log_max_size,
kSampleMessage + ":RollLogFileBySize"); kSampleMessage + ":RollLogFileBySize");
@ -321,8 +322,7 @@ TEST_F(AutoRollLoggerTest, CreateLoggerFromOptions) {
AutoRollLogger* auto_roll_logger = AutoRollLogger* auto_roll_logger =
dynamic_cast<AutoRollLogger*>(logger.get()); dynamic_cast<AutoRollLogger*>(logger.get());
ASSERT_TRUE(auto_roll_logger); ASSERT_TRUE(auto_roll_logger);
RollLogFileBySizeTest( RollLogFileBySizeTest(auto_roll_logger, options.max_log_file_size,
auto_roll_logger, options.max_log_file_size,
kSampleMessage + ":CreateLoggerFromOptions - size"); kSampleMessage + ":CreateLoggerFromOptions - size");
// Only roll by Time // Only roll by Time
@ -331,8 +331,7 @@ TEST_F(AutoRollLoggerTest, CreateLoggerFromOptions) {
options.max_log_file_size = 0; options.max_log_file_size = 0;
options.log_file_time_to_roll = 2; options.log_file_time_to_roll = 2;
ASSERT_OK(CreateLoggerFromOptions(kTestDir, options, &logger)); ASSERT_OK(CreateLoggerFromOptions(kTestDir, options, &logger));
auto_roll_logger = auto_roll_logger = dynamic_cast<AutoRollLogger*>(logger.get());
dynamic_cast<AutoRollLogger*>(logger.get());
RollLogFileByTimeTest(options.env->GetFileSystem(), nsc, auto_roll_logger, RollLogFileByTimeTest(options.env->GetFileSystem(), nsc, auto_roll_logger,
options.log_file_time_to_roll, options.log_file_time_to_roll,
kSampleMessage + ":CreateLoggerFromOptions - time"); kSampleMessage + ":CreateLoggerFromOptions - time");
@ -342,8 +341,7 @@ TEST_F(AutoRollLoggerTest, CreateLoggerFromOptions) {
options.max_log_file_size = 1024 * 5; options.max_log_file_size = 1024 * 5;
options.log_file_time_to_roll = 2; options.log_file_time_to_roll = 2;
ASSERT_OK(CreateLoggerFromOptions(kTestDir, options, &logger)); ASSERT_OK(CreateLoggerFromOptions(kTestDir, options, &logger));
auto_roll_logger = auto_roll_logger = dynamic_cast<AutoRollLogger*>(logger.get());
dynamic_cast<AutoRollLogger*>(logger.get());
RollLogFileBySizeTest(auto_roll_logger, options.max_log_file_size, RollLogFileBySizeTest(auto_roll_logger, options.max_log_file_size,
kSampleMessage + ":CreateLoggerFromOptions - both"); kSampleMessage + ":CreateLoggerFromOptions - both");
RollLogFileByTimeTest(options.env->GetFileSystem(), nsc, auto_roll_logger, RollLogFileByTimeTest(options.env->GetFileSystem(), nsc, auto_roll_logger,
@ -602,7 +600,6 @@ TEST_F(AutoRollLoggerTest, LogHeaderTest) {
// test_num == 0 -> standard call to Header() // test_num == 0 -> standard call to Header()
// test_num == 1 -> call to Log() with InfoLogLevel::HEADER_LEVEL // test_num == 1 -> call to Log() with InfoLogLevel::HEADER_LEVEL
for (int test_num = 0; test_num < 2; test_num++) { for (int test_num = 0; test_num < 2; test_num++) {
InitTestDb(); InitTestDb();
AutoRollLogger logger(FileSystem::Default(), SystemClock::Default(), AutoRollLogger logger(FileSystem::Default(), SystemClock::Default(),
@ -658,8 +655,8 @@ TEST_F(AutoRollLoggerTest, LogFileExistence) {
// Replace all slashes in the path so windows CompSpec does not // Replace all slashes in the path so windows CompSpec does not
// become confused // become confused
std::string testDir(kTestDir); std::string testDir(kTestDir);
std::replace_if(testDir.begin(), testDir.end(), std::replace_if(
[](char ch) { return ch == '/'; }, '\\'); testDir.begin(), testDir.end(), [](char ch) { return ch == '/'; }, '\\');
std::string deleteCmd = "if exist " + testDir + " rd /s /q " + testDir; std::string deleteCmd = "if exist " + testDir + " rd /s /q " + testDir;
#else #else
std::string deleteCmd = "rm -rf " + kTestDir; std::string deleteCmd = "rm -rf " + kTestDir;

@ -5,6 +5,7 @@
// //
#include "logging/env_logger.h" #include "logging/env_logger.h"
#include "test_util/testharness.h" #include "test_util/testharness.h"
#include "test_util/testutil.h" #include "test_util/testutil.h"

@ -44,9 +44,7 @@ EventLoggerStream::~EventLoggerStream() {
} }
} }
void EventLogger::Log(const JSONWriter& jwriter) { void EventLogger::Log(const JSONWriter& jwriter) { Log(logger_, jwriter); }
Log(logger_, jwriter);
}
void EventLogger::Log(Logger* logger, const JSONWriter& jwriter) { void EventLogger::Log(Logger* logger, const JSONWriter& jwriter) {
#ifdef ROCKSDB_PRINT_EVENTS_TO_STDOUT #ifdef ROCKSDB_PRINT_EVENTS_TO_STDOUT

@ -5,10 +5,10 @@
#pragma once #pragma once
#include <chrono>
#include <memory> #include <memory>
#include <sstream> #include <sstream>
#include <string> #include <string>
#include <chrono>
#include "logging/log_buffer.h" #include "logging/log_buffer.h"
#include "rocksdb/env.h" #include "rocksdb/env.h"
@ -157,7 +157,8 @@ class EventLoggerStream {
json_writer_ = new JSONWriter(); json_writer_ = new JSONWriter();
*this << "time_micros" *this << "time_micros"
<< std::chrono::duration_cast<std::chrono::microseconds>( << std::chrono::duration_cast<std::chrono::microseconds>(
std::chrono::system_clock::now().time_since_epoch()).count(); std::chrono::system_clock::now().time_since_epoch())
.count();
} }
} }
friend class EventLogger; friend class EventLogger;
@ -177,9 +178,7 @@ class EventLoggerStream {
// "file_size": 1909699} // "file_size": 1909699}
class EventLogger { class EventLogger {
public: public:
static const char* Prefix() { static const char* Prefix() { return "EVENT_LOG_v1"; }
return "EVENT_LOG_v1";
}
explicit EventLogger(Logger* logger) : logger_(logger) {} explicit EventLogger(Logger* logger) : logger_(logger) {}
EventLoggerStream Log() { return EventLoggerStream(logger_); } EventLoggerStream Log() { return EventLoggerStream(logger_); }

@ -3,9 +3,10 @@
// COPYING file in the root directory) and Apache 2.0 License // COPYING file in the root directory) and Apache 2.0 License
// (found in the LICENSE.Apache file in the root directory). // (found in the LICENSE.Apache file in the root directory).
#include "logging/event_logger.h"
#include <string> #include <string>
#include "logging/event_logger.h"
#include "test_util/testharness.h" #include "test_util/testharness.h"
namespace ROCKSDB_NAMESPACE { namespace ROCKSDB_NAMESPACE {

@ -5,13 +5,12 @@
#include "logging/log_buffer.h" #include "logging/log_buffer.h"
#include "port/sys_time.h"
#include "port/port.h" #include "port/port.h"
#include "port/sys_time.h"
namespace ROCKSDB_NAMESPACE { namespace ROCKSDB_NAMESPACE {
LogBuffer::LogBuffer(const InfoLogLevel log_level, LogBuffer::LogBuffer(const InfoLogLevel log_level, Logger* info_log)
Logger*info_log)
: log_level_(log_level), info_log_(info_log) {} : log_level_(log_level), info_log_(info_log) {}
void LogBuffer::AddLogToBuffer(size_t max_log_size, const char* format, void LogBuffer::AddLogToBuffer(size_t max_log_size, const char* format,

@ -6,6 +6,7 @@
#pragma once #pragma once
#include <ctime> #include <ctime>
#include "memory/arena.h" #include "memory/arena.h"
#include "port/sys_time.h" #include "port/sys_time.h"
#include "rocksdb/env.h" #include "rocksdb/env.h"

@ -15,10 +15,10 @@
// Helper macros that include information about file name and line number // Helper macros that include information about file name and line number
#define ROCKS_LOG_STRINGIFY(x) #x #define ROCKS_LOG_STRINGIFY(x) #x
#define ROCKS_LOG_TOSTRING(x) ROCKS_LOG_STRINGIFY(x) #define ROCKS_LOG_TOSTRING(x) ROCKS_LOG_STRINGIFY(x)
#define ROCKS_LOG_PREPEND_FILE_LINE(FMT) ("[%s:" ROCKS_LOG_TOSTRING(__LINE__) "] " FMT) #define ROCKS_LOG_PREPEND_FILE_LINE(FMT) \
("[%s:" ROCKS_LOG_TOSTRING(__LINE__) "] " FMT)
inline const char* RocksLogShorterFileName(const char* file) inline const char* RocksLogShorterFileName(const char* file) {
{
// 18 is the length of "logging/logging.h". // 18 is the length of "logging/logging.h".
// If the name of this file changed, please change this number, too. // If the name of this file changed, please change this number, too.
return file + (sizeof(__FILE__) > 18 ? sizeof(__FILE__) - 18 : 0); return file + (sizeof(__FILE__) > 18 ? sizeof(__FILE__) - 18 : 0);

Loading…
Cancel
Save