Skip to content

Commit

Permalink
fix logger
Browse files Browse the repository at this point in the history
  • Loading branch information
unixliang committed Sep 22, 2017
1 parent c899588 commit 60416c1
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 9 deletions.
25 changes: 19 additions & 6 deletions phxqueue/comm/logger.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ Unless required by applicable law or agreed to in writing, software distributed
#include <iostream>
#include <mutex>
#include <string>
#include <cstring>


using namespace std;
Expand Down Expand Up @@ -111,6 +112,11 @@ void Logger::SetLogFunc(LogFunc log_func) {
impl_->log_func = log_func;
}

void Logger::Log(const int log_level, const char *format, va_list args) {
if (impl_->log_func != nullptr) {
impl_->log_func(log_level, format, args);
}
}

enum PhxPaxosLogLevel {
PhxPaxosLogLevel_None = 0,
Expand All @@ -121,27 +127,34 @@ enum PhxPaxosLogLevel {
};

void LogFuncForPhxPaxos(const int log_level, const char *format, va_list args) {
auto phxqueue_log_level = LogLevel::None;
switch (log_level) {
case PhxPaxosLogLevel::PhxPaxosLogLevel_None:
phxqueue::comm::Logger::GetInstance()->LogError(format, args);
phxqueue_log_level = LogLevel::Error;
break;
case PhxPaxosLogLevel::PhxPaxosLogLevel_Error:
phxqueue::comm::Logger::GetInstance()->LogError(format, args);
phxqueue_log_level = LogLevel::Error;
break;
case PhxPaxosLogLevel::PhxPaxosLogLevel_Warning:
phxqueue::comm::Logger::GetInstance()->LogVerbose(format, args);
phxqueue_log_level = LogLevel::Verbose;
break;
case PhxPaxosLogLevel::PhxPaxosLogLevel_Info:
phxqueue::comm::Logger::GetInstance()->LogVerbose(format, args);
phxqueue_log_level = LogLevel::Verbose;
break;
case PhxPaxosLogLevel::PhxPaxosLogLevel_Verbose:
phxqueue::comm::Logger::GetInstance()->LogVerbose(format, args);
phxqueue_log_level = LogLevel::Verbose;
break;
}

if (phxqueue_log_level != LogLevel::None) {
if (strstr(format, "STATUS")) return;
if (strstr(format, "Lag msg")) return;
phxqueue::comm::Logger::GetInstance()->Log(static_cast<int>(phxqueue_log_level), format, args);
}
}

void LogFuncForPhxRpc(const int log_level, const char *format, va_list args) {
phxqueue::comm::Logger::GetInstance()->LogInfo(format, args);
phxqueue::comm::Logger::GetInstance()->Log(static_cast<int>(LogLevel::Info), format, args);
}


Expand Down
2 changes: 2 additions & 0 deletions phxqueue/comm/logger.h
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,8 @@ class Logger {

void SetLogFunc(LogFunc log_func);

void Log(const int log_level, const char *format, va_list args);

private:
class LoggerImpl;
std::unique_ptr<LoggerImpl> impl_;
Expand Down
2 changes: 1 addition & 1 deletion phxqueue/lock/lock.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -372,7 +372,7 @@ comm::RetCode Lock::PaxosInit(const string &mirror_dir_path) {
opts.oMyNode.SetIPPort(impl_->opt.ip, impl_->opt.paxos_port);
opts.bUseMembership = false;
opts.sLogStoragePath = nodedb_dir_path;
//opts.pLogFunc = comm::LogFuncForPhxPaxos;
opts.pLogFunc = comm::LogFuncForPhxPaxos;

opts.bUseCheckpointReplayer = true;
opts.iSyncInterval = topic_config->GetProto().topic().lock_paxos_fsync_interval();
Expand Down
2 changes: 1 addition & 1 deletion phxqueue/plugin/logger_google.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ int LoggerGoogle::GetLogger(const string &module_name, const string &log_path,


void LoggerGoogle::Log(const int log_level, const char *format, va_list args) {
char buf[1024]{0};
char buf[1024] = {0};
vsnprintf(buf, sizeof(buf), format, args);

int google_log_level{LogLevel2GoogleLogLevel(static_cast<comm::LogLevel>(log_level))};
Expand Down
2 changes: 1 addition & 1 deletion phxqueue/store/store.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,7 @@ comm::RetCode Store::PaxosInit() {
opts.oMyNode.SetIPPort(impl_->opt.ip, impl_->opt.paxos_port);
opts.bUseMembership = false;
opts.sLogStoragePath = nodedb_dir_path;
//opts.pLogFunc = comm::LogFuncForPhxPaxos;
opts.pLogFunc = comm::LogFuncForPhxPaxos;

opts.bUseCheckpointReplayer = false;
opts.iSyncInterval = topic_config->GetProto().topic().store_paxos_fsync_interval();
Expand Down

0 comments on commit 60416c1

Please sign in to comment.