Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/main/CommandHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -463,6 +463,7 @@ void
CommandHandler::logRotate(std::string const& params, std::string& retStr)
{
retStr = "Log rotate...";
Logging::rotateLogFile();
}

void
Expand Down
20 changes: 20 additions & 0 deletions src/util/Logging.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
namespace stellar
{
el::Configurations Logging::gDefaultConf;
int32_t Logging::logFileIndex;

void
Logging::setFmt(std::string const& peerID, bool timestamps)
Expand Down Expand Up @@ -60,7 +61,10 @@ Logging::init()
gDefaultConf.setToDefault();
gDefaultConf.setGlobally(el::ConfigurationType::ToStandardOutput, "true");
gDefaultConf.setGlobally(el::ConfigurationType::ToFile, "false");
gDefaultConf.setGlobally(el::ConfigurationType::MaxLogFileSize, "1");
setFmt("<startup>");
logFileIndex = 0;
el::Helpers::installPreRollOutCallback(rolloutHandler);
}

void
Expand All @@ -71,6 +75,22 @@ Logging::setLoggingToFile(std::string const& filename)
el::Loggers::reconfigureAllLoggers(gDefaultConf);
}

void
Logging::rolloutHandler(const char* filename, std::size_t size) {
// size is there to match easylogging++ library template
std::stringstream ss_new_filename;
ss_new_filename << filename << "." << ++logFileIndex;
std::rename(filename, ss_new_filename.str().c_str());
el::Loggers::removeFlag(el::LoggingFlag::StrictLogFileSizeCheck);
}


void
Logging::rotateLogFile()
{
el::Loggers::addFlag(el::LoggingFlag::StrictLogFileSizeCheck);
}

el::Level
Logging::getLogLevel(std::string const& partition)
{
Expand Down
3 changes: 3 additions & 0 deletions src/util/Logging.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,14 @@ namespace stellar
class Logging
{
static el::Configurations gDefaultConf;
static int32_t logFileIndex;

public:
static void init();
static void setFmt(std::string const& peerID, bool timestamps = true);
static void setLoggingToFile(std::string const& filename);
static void rotateLogFile();
static void rolloutHandler(const char* filename, std::size_t size);
static void setLogLevel(el::Level level, const char* partition);
static el::Level getLLfromString(std::string const& levelName);
static el::Level getLogLevel(std::string const& partition);
Expand Down