Skip to content

Commit

Permalink
Run clang format on logging folder (#10861)
Browse files Browse the repository at this point in the history
Summary: Pull Request resolved: #10861

Test Plan: CircleCI jobs

Reviewed By: siying

Differential Revision: D40654198

Pulled By: akankshamahajan15

fbshipit-source-id: 787be2575578b3aa3bd985509f96fdb9e02f7ad7
  • Loading branch information
akankshamahajan15 authored and facebook-github-bot committed Oct 25, 2022
1 parent ee3dbdc commit 935aae3
Show file tree
Hide file tree
Showing 10 changed files with 42 additions and 50 deletions.
6 changes: 3 additions & 3 deletions logging/auto_roll_logger.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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;
Expand Down
10 changes: 3 additions & 7 deletions logging/auto_roll_logger.h
Original file line number Diff line number Diff line change
Expand Up @@ -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_) {
Expand Down Expand Up @@ -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_; }

Expand Down Expand Up @@ -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_;
Expand Down
43 changes: 20 additions & 23 deletions logging/auto_roll_logger_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -319,20 +320,18 @@ 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();
InitTestDb();
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");
Expand All @@ -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,
Expand Down Expand Up @@ -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();
}
Expand Down Expand Up @@ -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();
}
Expand Down Expand Up @@ -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(),
Expand Down Expand Up @@ -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
Expand All @@ -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;
Expand Down
1 change: 1 addition & 0 deletions logging/env_logger_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
//

#include "logging/env_logger.h"

#include "test_util/testharness.h"
#include "test_util/testutil.h"

Expand Down
4 changes: 1 addition & 3 deletions logging/event_logger.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
9 changes: 4 additions & 5 deletions logging/event_logger.h
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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;
Expand All @@ -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_); }
Expand Down
3 changes: 2 additions & 1 deletion logging/event_logger_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
5 changes: 2 additions & 3 deletions logging/log_buffer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
5 changes: 3 additions & 2 deletions logging/log_buffer.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#pragma once

#include <ctime>

#include "memory/arena.h"
#include "port/sys_time.h"
#include "rocksdb/env.h"
Expand Down Expand Up @@ -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_;
Expand Down
6 changes: 3 additions & 3 deletions logging/logging.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 935aae3

Please sign in to comment.