Skip to content

Commit

Permalink
codemod: LOG -> WLOG (and VLOG and _IF variants) with common prefix f…
Browse files Browse the repository at this point in the history
…or easier extraction in prod logs of svcs

Summary: codemod: LOG -> WLOG (and VLOG and _IF variants) with common prefix for easier extraction in prod logs of svcs

Reviewed By: uddipta

Differential Revision: D3044475

fb-gh-sync-id: 7c2a1e4c0fc7c10973ef1f07a7039fae5d1ac0dc
shipit-source-id: 7c2a1e4c0fc7c10973ef1f07a7039fae5d1ac0dc
  • Loading branch information
ldemailly committed Mar 12, 2016
1 parent 72ac1c6 commit ba6ecfe
Show file tree
Hide file tree
Showing 39 changed files with 942 additions and 919 deletions.
7 changes: 7 additions & 0 deletions ErrorCodes.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,13 @@
namespace facebook {
namespace wdt {

// Call regular google log but prefix with wdt for easier extraction later
#define WDT_LOG_PREFIX "wdt>\t"
#define WLOG(X) LOG(X) << WDT_LOG_PREFIX
#define WVLOG(X) VLOG(X) << WDT_LOG_PREFIX
#define WLOG_IF(X, Y) LOG_IF(X, Y) << WDT_LOG_PREFIX
#define WVLOG_IF(X, Y) VLOG_IF(X, Y) << WDT_LOG_PREFIX

// For now just does regular check, for some library embedding may consider
// skipping or being DCHECK
#define WDT_CHECK CHECK
Expand Down
30 changes: 15 additions & 15 deletions Protocol.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ const std::string Protocol::getFullVersion() {
int Protocol::negotiateProtocol(int requestedProtocolVersion,
int curProtocolVersion) {
if (requestedProtocolVersion < 10) {
LOG(WARNING) << "Can not handle protocol " << requestedProtocolVersion;
WLOG(WARNING) << "Can not handle protocol " << requestedProtocolVersion;
return 0;
}
return std::min<int>(curProtocolVersion, requestedProtocolVersion);
Expand Down Expand Up @@ -162,7 +162,7 @@ bool Protocol::decodeHeader(int receiverProtocolVersion, char *src,
blockDetails.fileSize = decodeInt(br);
if (receiverProtocolVersion >= HEADER_FLAG_AND_PREV_SEQ_ID_VERSION) {
if (!(br.size() >= 1)) {
LOG(ERROR) << "Invalid (too short) input " << string(src + off, max);
WLOG(ERROR) << "Invalid (too short) input " << string(src + off, max);
return false;
}
uint8_t flags = br.front();
Expand All @@ -175,7 +175,7 @@ bool Protocol::decodeHeader(int receiverProtocolVersion, char *src,
}
}
} catch (const std::exception &ex) {
LOG(ERROR) << "got exception " << folly::exceptionStr(ex);
WLOG(ERROR) << "got exception " << folly::exceptionStr(ex);
return false;
}
off = br.start() - (uint8_t *)src;
Expand Down Expand Up @@ -226,7 +226,7 @@ bool Protocol::decodeCheckpoints(int protocolVersion, char *src, int64_t &off,
checkpoints.emplace_back(checkpoint);
}
} catch (const std::exception &ex) {
LOG(ERROR) << "got exception " << folly::exceptionStr(ex);
WLOG(ERROR) << "got exception " << folly::exceptionStr(ex);
return false;
}
return true;
Expand All @@ -250,7 +250,7 @@ bool Protocol::decodeDone(int protocolVersion, char *src, int64_t &off,
bytesSent = decodeInt(br);
}
} catch (const std::exception &ex) {
LOG(ERROR) << "got exception " << folly::exceptionStr(ex);
WLOG(ERROR) << "got exception " << folly::exceptionStr(ex);
return false;
}
off = br.start() - (uint8_t *)src;
Expand All @@ -269,7 +269,7 @@ bool Protocol::decodeSize(char *src, int64_t &off, int64_t max,
try {
totalNumBytes = decodeInt(br);
} catch (const std::exception &ex) {
LOG(ERROR) << "got exception " << folly::exceptionStr(ex);
WLOG(ERROR) << "got exception " << folly::exceptionStr(ex);
return false;
}
off = br.start() - (uint8_t *)src;
Expand Down Expand Up @@ -328,7 +328,7 @@ bool Protocol::decodeChunkInfo(folly::ByteRange &br, char *src, int64_t max,
chunk.start_ = decodeInt(br);
chunk.end_ = decodeInt(br);
} catch (const std::exception &ex) {
LOG(ERROR) << "got exception " << folly::exceptionStr(ex);
WLOG(ERROR) << "got exception " << folly::exceptionStr(ex);
return false;
}
int64_t off = br.start() - (uint8_t *)src;
Expand Down Expand Up @@ -371,7 +371,7 @@ bool Protocol::decodeFileChunksInfo(folly::ByteRange &br, char *src,
fileChunksInfo.addChunk(chunk);
}
} catch (const std::exception &ex) {
LOG(ERROR) << "got exception " << folly::exceptionStr(ex);
WLOG(ERROR) << "got exception " << folly::exceptionStr(ex);
return false;
}
int64_t off = br.start() - (uint8_t *)src;
Expand All @@ -393,9 +393,9 @@ int64_t Protocol::encodeFileChunksInfoList(
const FileChunksInfo &fileChunksInfo = fileChunksInfoList[i];
int64_t maxLength = maxEncodeLen(fileChunksInfo);
if (maxLength + oldOffset > bufSize) {
LOG(WARNING) << "Chunk info for " << fileChunksInfo.getFileName()
<< " can not be encoded in a buffer of size " << bufSize
<< ", Ignoring.";
WLOG(WARNING) << "Chunk info for " << fileChunksInfo.getFileName()
<< " can not be encoded in a buffer of size " << bufSize
<< ", Ignoring.";
continue;
}
if (maxLength + off >= bufSize) {
Expand Down Expand Up @@ -451,7 +451,7 @@ bool Protocol::decodeVersion(char *src, int64_t &off, int64_t max,
try {
senderProtocolVersion = decodeInt(br);
} catch (const std::exception &ex) {
LOG(ERROR) << "got exception " << folly::exceptionStr(ex);
WLOG(ERROR) << "got exception " << folly::exceptionStr(ex);
return ERROR;
}
off = br.start() - (uint8_t *)src;
Expand All @@ -476,7 +476,7 @@ bool Protocol::decodeSettings(int protocolVersion, char *src, int64_t &off,
br.pop_front();
}
} catch (const std::exception &ex) {
LOG(ERROR) << "got exception " << folly::exceptionStr(ex);
WLOG(ERROR) << "got exception " << folly::exceptionStr(ex);
return false;
}
off = br.start() - (uint8_t *)src;
Expand All @@ -503,7 +503,7 @@ bool Protocol::decodeEncryptionSettings(char *src, int64_t &off, int64_t max,
return false;
}
} catch (const std::exception &ex) {
LOG(ERROR) << "got exception " << folly::exceptionStr(ex);
WLOG(ERROR) << "got exception " << folly::exceptionStr(ex);
return false;
}
off = br.start() - (uint8_t *)src;
Expand Down Expand Up @@ -532,7 +532,7 @@ bool Protocol::decodeFooter(char *src, int64_t &off, int64_t max,
checksum = decodeInt(br);
}
} catch (const std::exception &ex) {
LOG(ERROR) << "got exception " << folly::exceptionStr(ex);
WLOG(ERROR) << "got exception " << folly::exceptionStr(ex);
return false;
}
off = br.start() - (uint8_t *)src;
Expand Down
91 changes: 46 additions & 45 deletions Receiver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,9 @@ using std::vector;
namespace facebook {
namespace wdt {
void Receiver::addCheckpoint(Checkpoint checkpoint) {
LOG(INFO) << "Adding global checkpoint " << checkpoint.port << " "
<< checkpoint.numBlocks << " " << checkpoint.lastBlockReceivedBytes;
WLOG(INFO) << "Adding global checkpoint " << checkpoint.port << " "
<< checkpoint.numBlocks << " "
<< checkpoint.lastBlockReceivedBytes;
checkpoints_.emplace_back(checkpoint);
}

Expand All @@ -45,7 +46,7 @@ std::vector<Checkpoint> Receiver::getNewCheckpoints(int startIndex) {

Receiver::Receiver(const WdtTransferRequest &transferRequest)
: transferLogManager_(options_) {
LOG(INFO) << "WDT Receiver " << Protocol::getFullVersion();
WLOG(INFO) << "WDT Receiver " << Protocol::getFullVersion();
transferRequest_ = transferRequest;
}

Expand All @@ -62,8 +63,8 @@ void Receiver::traverseDestinationDir(
if (fileInfo->relPath == kWdtLogName ||
fileInfo->relPath == kWdtBuggyLogName) {
// do not include wdt log files
VLOG(1) << "Removing " << fileInfo->relPath
<< " from the list of existing files";
WVLOG(1) << "Removing " << fileInfo->relPath
<< " from the list of existing files";
continue;
}
FileChunksInfo chunkInfo(fileInfo->seqId, fileInfo->relPath,
Expand Down Expand Up @@ -91,8 +92,8 @@ void Receiver::startNewGlobalSession(const std::string &peerIp) {
}
}
hasNewTransferStarted_.store(true);
LOG(INFO) << "Starting new transfer, peerIp " << peerIp << " , transfer id "
<< getTransferId();
WLOG(INFO) << "Starting new transfer, peerIp " << peerIp << " , transfer id "
<< getTransferId();
}

bool Receiver::hasNewTransferStarted() const {
Expand All @@ -102,10 +103,10 @@ bool Receiver::hasNewTransferStarted() const {
void Receiver::endCurGlobalSession() {
setTransferStatus(FINISHED);
if (!hasNewTransferStarted_) {
LOG(WARNING) << "WDT transfer did not start, no need to end session";
WLOG(WARNING) << "WDT transfer did not start, no need to end session";
return;
}
LOG(INFO) << "Ending the transfer " << getTransferId();
WLOG(INFO) << "Ending the transfer " << getTransferId();
if (throttler_) {
throttler_->deRegisterTransfer();
}
Expand All @@ -119,8 +120,8 @@ void Receiver::endCurGlobalSession() {

const WdtTransferRequest &Receiver::init() {
if (validateTransferRequest() != OK) {
LOG(ERROR) << "Couldn't validate the transfer request "
<< transferRequest_.getLogSafeString();
WLOG(ERROR) << "Couldn't validate the transfer request "
<< transferRequest_.getLogSafeString();
return transferRequest_;
}
checkAndUpdateBufferSize();
Expand All @@ -146,7 +147,7 @@ const WdtTransferRequest &Receiver::init() {
}
ErrorCode errCode = transferLogManager_.openLog();
if (errCode != OK) {
LOG(ERROR) << "Failed to open transfer log " << errorCodeToStr(errCode);
WLOG(ERROR) << "Failed to open transfer log " << errorCodeToStr(errCode);
transferRequest_.errorCode = errCode;
return transferRequest_;
}
Expand All @@ -163,26 +164,26 @@ const WdtTransferRequest &Receiver::init() {
bool encrypt = (encryptionType != ENC_NONE &&
protocolVersion_ >= Protocol::ENCRYPTION_V1_VERSION);
if (encrypt) {
LOG(INFO) << encryptionTypeToStr(encryptionType)
<< " encryption is enabled for this transfer ";
WLOG(INFO) << encryptionTypeToStr(encryptionType)
<< " encryption is enabled for this transfer ";
if (!transferRequest_.encryptionData.isSet()) {
LOG(INFO) << "Receiver generating encryption key for type "
<< encryptionTypeToStr(encryptionType);
WLOG(INFO) << "Receiver generating encryption key for type "
<< encryptionTypeToStr(encryptionType);
transferRequest_.encryptionData =
EncryptionParams::generateEncryptionParams(encryptionType);
}
if (!transferRequest_.encryptionData.isSet()) {
LOG(ERROR) << "Unable to generate encryption key for type "
<< encryptionTypeToStr(encryptionType);
WLOG(ERROR) << "Unable to generate encryption key for type "
<< encryptionTypeToStr(encryptionType);
transferRequest_.errorCode = ENCRYPTION_ERROR;
return transferRequest_;
}
} else {
if (encryptionType != ENC_NONE) {
LOG(WARNING) << "Encryption is enabled, but protocol version is "
<< protocolVersion_
<< ", minimum version required for encryption is "
<< Protocol::ENCRYPTION_V1_VERSION;
WLOG(WARNING) << "Encryption is enabled, but protocol version is "
<< protocolVersion_
<< ", minimum version required for encryption is "
<< Protocol::ENCRYPTION_V1_VERSION;
}
transferRequest_.encryptionData.erase();
}
Expand All @@ -200,8 +201,8 @@ const WdtTransferRequest &Receiver::init() {
++numSuccessfulInitThreads;
}
}
LOG(INFO) << "Registered " << numSuccessfulInitThreads
<< " successful sockets";
WLOG(INFO) << "Registered " << numSuccessfulInitThreads
<< " successful sockets";
ErrorCode code = OK;
const size_t targetSize = transferRequest_.ports.size();
// TODO: replace with getNumPorts/thread
Expand Down Expand Up @@ -252,14 +253,14 @@ const std::string &Receiver::getDir() {

void Receiver::setRecoveryId(const std::string &recoveryId) {
recoveryId_ = recoveryId;
LOG(INFO) << "recovery id " << recoveryId_;
WLOG(INFO) << "recovery id " << recoveryId_;
}

Receiver::~Receiver() {
TransferStatus status = getTransferStatus();
if (status == ONGOING) {
LOG(WARNING) << "There is an ongoing transfer and the destructor"
<< " is being called. Trying to finish the transfer";
WLOG(WARNING) << "There is an ongoing transfer and the destructor"
<< " is being called. Trying to finish the transfer";
abort(ABORTED_BY_APPLICATION);
}
finish();
Expand All @@ -284,19 +285,19 @@ std::unique_ptr<TransferReport> Receiver::finish() {
std::unique_lock<std::mutex> instanceLock(instanceManagementMutex_);
TransferStatus status = getTransferStatus();
if (status == NOT_STARTED) {
LOG(WARNING) << "Even though transfer has not started, finish is called";
WLOG(WARNING) << "Even though transfer has not started, finish is called";
// getTransferReport will set the error code to ERROR
return getTransferReport();
}
if (status == THREADS_JOINED) {
LOG(WARNING) << "Threads have already been joined. Returning the "
<< "transfer report";
WLOG(WARNING) << "Threads have already been joined. Returning the "
<< "transfer report";
return getTransferReport();
}
if (!isJoinable_) {
// TODO: don't complain about this when coming from runForever()
LOG(WARNING) << "The receiver is not joinable. The threads will never"
<< " finish and this method will never return";
WLOG(WARNING) << "The receiver is not joinable. The threads will never"
<< " finish and this method will never return";
}
for (auto &receiverThread : receiverThreads_) {
receiverThread->finish();
Expand All @@ -320,8 +321,8 @@ std::unique_ptr<TransferReport> Receiver::finish() {
}
logPerfStats();

LOG(WARNING) << "WDT receiver's transfer has been finished";
LOG(INFO) << *report;
WLOG(WARNING) << "WDT receiver's transfer has been finished";
WLOG(INFO) << *report;
return report;
}

Expand All @@ -335,10 +336,10 @@ std::unique_ptr<TransferReport> Receiver::getTransferReport() {
TransferStatus status = getTransferStatus();
ErrorCode errCode = transferReport->getSummary().getErrorCode();
if (status == NOT_STARTED && errCode == OK) {
LOG(INFO) << "Transfer not started, setting the error code to ERROR";
WLOG(INFO) << "Transfer not started, setting the error code to ERROR";
transferReport->setErrorCode(ERROR);
}
VLOG(1) << "Summary code " << errCode;
WVLOG(1) << "Summary code " << errCode;
return transferReport;
}

Expand Down Expand Up @@ -385,8 +386,8 @@ void Receiver::progressTracker() {
std::chrono::time_point<Clock> lastUpdateTime = Clock::now();
int intervalsSinceLastUpdate = 0;
double currentThroughput = 0;
LOG(INFO) << "Progress reporter updating every "
<< progressReportIntervalMillis << " ms";
WLOG(INFO) << "Progress reporter updating every "
<< progressReportIntervalMillis << " ms";
auto waitingTime = std::chrono::milliseconds(progressReportIntervalMillis);
int64_t totalSenderBytes = -1;
while (true) {
Expand Down Expand Up @@ -437,20 +438,20 @@ void Receiver::logPerfStats() const {
for (auto &receiverThread : receiverThreads_) {
globalPerfReport += receiverThread->getPerfReport();
}
LOG(INFO) << globalPerfReport;
WLOG(INFO) << globalPerfReport;
}

ErrorCode Receiver::start() {
WDT_CHECK_EQ(getTransferStatus(), NOT_STARTED)
<< "There is already a transfer running on this instance of receiver";
startTime_ = Clock::now();
LOG(INFO) << "Starting (receiving) server on ports [ "
<< transferRequest_.ports << "] Target dir : " << destDir_;
WLOG(INFO) << "Starting (receiving) server on ports [ "
<< transferRequest_.ports << "] Target dir : " << destDir_;
// TODO do the init stuff here
if (!throttler_) {
configureThrottler();
} else {
LOG(INFO) << "Throttler set externally. Throttler : " << *throttler_;
WLOG(INFO) << "Throttler set externally. Throttler : " << *throttler_;
}
setTransferStatus(ONGOING);
while (true) {
Expand Down Expand Up @@ -488,11 +489,11 @@ void Receiver::addTransferLogHeader(bool isBlockMode, bool isSenderResuming) {
}
bool invalidationEntryNeeded = false;
if (!isSenderResuming) {
LOG(INFO) << "Sender is not in resumption mode. Invalidating directory.";
WLOG(INFO) << "Sender is not in resumption mode. Invalidating directory.";
invalidationEntryNeeded = true;
} else if (options_.resume_using_dir_tree && isBlockMode) {
LOG(INFO) << "Sender is running in block mode, but receiver is running in "
"size based resumption mode. Invalidating directory.";
WLOG(INFO) << "Sender is running in block mode, but receiver is running in "
"size based resumption mode. Invalidating directory.";
invalidationEntryNeeded = true;
}
if (invalidationEntryNeeded) {
Expand Down
Loading

0 comments on commit ba6ecfe

Please sign in to comment.