Skip to content

Commit

Permalink
Add batched logger
Browse files Browse the repository at this point in the history
  • Loading branch information
codablock committed Jan 9, 2019
1 parent 0df3871 commit 9d25bb1
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ BITCOIN_CORE_H = \
addrman.h \
alert.h \
base58.h \
batchedlogger.h \
bip39.h \
bip39_english.h \
blockencodings.h \
Expand Down Expand Up @@ -224,6 +225,7 @@ libdash_server_a_SOURCES = \
addrman.cpp \
addrdb.cpp \
alert.cpp \
batchedlogger.cpp \
bloom.cpp \
blockencodings.cpp \
chain.cpp \
Expand Down
25 changes: 25 additions & 0 deletions src/batchedlogger.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
// Copyright (c) 2018 The Dash Core developers
// Distributed under the MIT/X11 software license, see the accompanying
// file COPYING or http://www.opensource.org/licenses/mit-license.php.

#include "batchedlogger.h"
#include "util.h"

CBatchedLogger::CBatchedLogger(const std::string& _header) :
header(_header)
{
}

CBatchedLogger::~CBatchedLogger()
{
Flush();
}

void CBatchedLogger::Flush()
{
if (msg.empty()) {
return;
}
LogPrintStr(strprintf("%s:\n%s", header, msg));
msg.clear();
}
28 changes: 28 additions & 0 deletions src/batchedlogger.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
// Copyright (c) 2018 The Dash Core developers
// Distributed under the MIT/X11 software license, see the accompanying
// file COPYING or http://www.opensource.org/licenses/mit-license.php.

#ifndef DASH_BATCHEDLOGGER_H
#define DASH_BATCHEDLOGGER_H

#include "tinyformat.h"

class CBatchedLogger
{
private:
std::string header;
std::string msg;
public:
CBatchedLogger(const std::string& _header);
virtual ~CBatchedLogger();

template<typename... Args>
void Printf(const std::string& fmt, const Args&... args)
{
msg += strprintf(fmt, args...);
}

void Flush();
};

#endif//DASH_BATCHEDLOGGER_H

0 comments on commit 9d25bb1

Please sign in to comment.