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. 6
      logging/auto_roll_logger.cc
  2. 10
      logging/auto_roll_logger.h
  3. 43
      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. 5
      logging/log_buffer.h
  10. 6
      logging/logging.h

@ -90,8 +90,8 @@ void AutoRollLogger::RollLogFile() {
uint64_t now = clock_->NowMicros();
std::string old_fname;
do {
old_fname = OldInfoLogFileName(
dbname_, now, db_absolute_path_, db_log_dir_);
old_fname =
OldInfoLogFileName(dbname_, now, db_absolute_path_, db_log_dir_);
now++;
} 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
@ -173,7 +173,7 @@ std::string AutoRollLogger::ValistToString(const char* format,
char buffer[MAXBUFFERSIZE];
int count = vsnprintf(buffer, MAXBUFFERSIZE, format, args);
(void) count;
(void)count;
assert(count >= 0);
return buffer;

@ -40,9 +40,7 @@ class AutoRollLogger : public Logger {
virtual void LogHeader(const char* format, va_list ap) override;
// check if the logger has encountered any problem.
Status GetStatus() {
return status_;
}
Status GetStatus() { return status_; }
size_t GetLogFileSize() const override {
if (!logger_) {
@ -101,9 +99,7 @@ class AutoRollLogger : public Logger {
}
// Expose the log file path for testing purpose
std::string TEST_log_fname() const {
return log_fname_;
}
std::string TEST_log_fname() const { return log_fname_; }
uint64_t TEST_ctime() const { return ctime_; }
@ -134,7 +130,7 @@ class AutoRollLogger : public Logger {
std::string ValistToString(const char* format, va_list args) const;
// Write the logs marked as headers to the new log file
void WriteHeaderInfo();
std::string log_fname_; // Current active info log's file name.
std::string log_fname_; // Current active info log's file name.
std::string dbname_;
std::string db_log_dir_;
std::string db_absolute_path_;

@ -64,8 +64,9 @@ class AutoRollLoggerTest : public testing::Test {
ASSERT_TRUE(system(deleteDbDirCmd.c_str()) == 0);
std::string testDir(kTestDir);
std::replace_if(testDir.begin(), testDir.end(),
[](char ch) { return ch == '/'; }, '\\');
std::replace_if(
testDir.begin(), testDir.end(), [](char ch) { return ch == '/'; },
'\\');
std::string deleteCmd = "if exist " + testDir + " rd /s /q " + testDir;
#else
std::string deleteCmd = "rm -rf " + kTestDir + " " + kTestDbDir;
@ -203,15 +204,15 @@ void AutoRollLoggerTest::RollLogFileByTimeTest(
}
TEST_F(AutoRollLoggerTest, RollLogFileBySize) {
InitTestDb();
size_t log_max_size = 1024 * 5;
size_t keep_log_file_num = 10;
InitTestDb();
size_t log_max_size = 1024 * 5;
size_t keep_log_file_num = 10;
AutoRollLogger logger(FileSystem::Default(), SystemClock::Default(),
kTestDir, "", log_max_size, 0, keep_log_file_num);
AutoRollLogger logger(FileSystem::Default(), SystemClock::Default(), kTestDir,
"", log_max_size, 0, keep_log_file_num);
RollLogFileBySizeTest(&logger, log_max_size,
kSampleMessage + ":RollLogFileBySize");
RollLogFileBySizeTest(&logger, log_max_size,
kSampleMessage + ":RollLogFileBySize");
}
TEST_F(AutoRollLoggerTest, RollLogFileByTime) {
@ -319,11 +320,10 @@ TEST_F(AutoRollLoggerTest, CreateLoggerFromOptions) {
options.max_log_file_size = 1024;
ASSERT_OK(CreateLoggerFromOptions(kTestDir, options, &logger));
AutoRollLogger* auto_roll_logger =
dynamic_cast<AutoRollLogger*>(logger.get());
dynamic_cast<AutoRollLogger*>(logger.get());
ASSERT_TRUE(auto_roll_logger);
RollLogFileBySizeTest(
auto_roll_logger, options.max_log_file_size,
kSampleMessage + ":CreateLoggerFromOptions - size");
RollLogFileBySizeTest(auto_roll_logger, options.max_log_file_size,
kSampleMessage + ":CreateLoggerFromOptions - size");
// Only roll by Time
options.env = nse.get();
@ -331,8 +331,7 @@ TEST_F(AutoRollLoggerTest, CreateLoggerFromOptions) {
options.max_log_file_size = 0;
options.log_file_time_to_roll = 2;
ASSERT_OK(CreateLoggerFromOptions(kTestDir, options, &logger));
auto_roll_logger =
dynamic_cast<AutoRollLogger*>(logger.get());
auto_roll_logger = dynamic_cast<AutoRollLogger*>(logger.get());
RollLogFileByTimeTest(options.env->GetFileSystem(), nsc, auto_roll_logger,
options.log_file_time_to_roll,
kSampleMessage + ":CreateLoggerFromOptions - time");
@ -342,8 +341,7 @@ TEST_F(AutoRollLoggerTest, CreateLoggerFromOptions) {
options.max_log_file_size = 1024 * 5;
options.log_file_time_to_roll = 2;
ASSERT_OK(CreateLoggerFromOptions(kTestDir, options, &logger));
auto_roll_logger =
dynamic_cast<AutoRollLogger*>(logger.get());
auto_roll_logger = dynamic_cast<AutoRollLogger*>(logger.get());
RollLogFileBySizeTest(auto_roll_logger, options.max_log_file_size,
kSampleMessage + ":CreateLoggerFromOptions - both");
RollLogFileByTimeTest(options.env->GetFileSystem(), nsc, auto_roll_logger,
@ -527,7 +525,7 @@ TEST_F(AutoRollLoggerTest, InfoLogLevel) {
}
std::ifstream inFile(AutoRollLoggerTest::kLogFile.c_str());
size_t lines = std::count(std::istreambuf_iterator<char>(inFile),
std::istreambuf_iterator<char>(), '\n');
std::istreambuf_iterator<char>(), '\n');
ASSERT_EQ(log_lines, lines);
inFile.close();
}
@ -567,7 +565,7 @@ TEST_F(AutoRollLoggerTest, Close) {
std::ifstream inFile(AutoRollLoggerTest::kLogFile.c_str());
size_t lines = std::count(std::istreambuf_iterator<char>(inFile),
std::istreambuf_iterator<char>(), '\n');
std::istreambuf_iterator<char>(), '\n');
ASSERT_EQ(log_lines, lines);
inFile.close();
}
@ -602,7 +600,6 @@ TEST_F(AutoRollLoggerTest, LogHeaderTest) {
// test_num == 0 -> standard call to Header()
// test_num == 1 -> call to Log() with InfoLogLevel::HEADER_LEVEL
for (int test_num = 0; test_num < 2; test_num++) {
InitTestDb();
AutoRollLogger logger(FileSystem::Default(), SystemClock::Default(),
@ -640,7 +637,7 @@ TEST_F(AutoRollLoggerTest, LogHeaderTest) {
const auto oldfiles = GetOldFileNames(newfname);
ASSERT_EQ(oldfiles.size(), (size_t) 2);
ASSERT_EQ(oldfiles.size(), (size_t)2);
for (auto& oldfname : oldfiles) {
// verify that the files rolled over
@ -658,8 +655,8 @@ TEST_F(AutoRollLoggerTest, LogFileExistence) {
// Replace all slashes in the path so windows CompSpec does not
// become confused
std::string testDir(kTestDir);
std::replace_if(testDir.begin(), testDir.end(),
[](char ch) { return ch == '/'; }, '\\');
std::replace_if(
testDir.begin(), testDir.end(), [](char ch) { return ch == '/'; }, '\\');
std::string deleteCmd = "if exist " + testDir + " rd /s /q " + testDir;
#else
std::string deleteCmd = "rm -rf " + kTestDir;

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

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

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

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

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

@ -6,6 +6,7 @@
#pragma once
#include <ctime>
#include "memory/arena.h"
#include "port/sys_time.h"
#include "rocksdb/env.h"
@ -35,8 +36,8 @@ class LogBuffer {
private:
// One log entry with its timestamp
struct BufferedLog {
port::TimeVal now_tv; // Timestamp of the log
char message[1]; // Beginning of log message
port::TimeVal now_tv; // Timestamp of the log
char message[1]; // Beginning of log message
};
const InfoLogLevel log_level_;

@ -15,10 +15,10 @@
// Helper macros that include information about file name and line number
#define ROCKS_LOG_STRINGIFY(x) #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".
// If the name of this file changed, please change this number, too.
return file + (sizeof(__FILE__) > 18 ? sizeof(__FILE__) - 18 : 0);

Loading…
Cancel
Save