Unverified Commit 0cb51886 authored by Mccaskey, Alex's avatar Mccaskey, Alex Committed by GitHub

Merge pull request #231 from tnguyen-ornl/tnguyen/mpi-log

Added ability to add a custom prefix to the XACC log filename
parents f369b2da 80d89f97
Pipeline #111538 passed with stage
in 14 minutes and 13 seconds
......@@ -217,7 +217,7 @@ void XACCLogger::createFileLogger() {
const std::string DEFAULT_FILE_NAME_PREFIX = "xacc_log_";
const std::string DEFAULT_FILE_NAME_POSTFIX = ".txt";
const std::string fileName = DEFAULT_FILE_NAME_PREFIX + getCurrentTimeForFileName() + DEFAULT_FILE_NAME_POSTFIX;
const std::string fileName = logFileNamePrefix + "_" + DEFAULT_FILE_NAME_PREFIX + getCurrentTimeForFileName() + DEFAULT_FILE_NAME_POSTFIX;
// Create a file logger using the timestamped filename in the logs folder.
fileLogger = spdlog::basic_logger_mt(loggerName, logDir + "/" + fileName);
}
......@@ -225,7 +225,7 @@ void XACCLogger::createFileLogger() {
fileLogger->set_level(spdlog::level::info);
}
void XACCLogger::logToFile(bool enable) {
void XACCLogger::logToFile(bool enable, const std::string& fileNamePrefix) {
// Switching the current setting
if (enable != useFile) {
// Always dump any enqueued messages before switching.
......@@ -234,6 +234,7 @@ void XACCLogger::logToFile(bool enable) {
// log message to the appropriate logger.
useFile = enable;
}
logFileNamePrefix = fileNamePrefix;
}
void XACCLogger::setLoggingLevel(int level) {
......
......@@ -164,6 +164,9 @@ protected:
std::vector<LoggingLevelNotification> loggingLevelSubscribers;
std::queue<std::string> logQueue;
// Custom filename prefix (if logging to file)
std::string logFileNamePrefix;
XACCLogger();
......@@ -193,7 +196,8 @@ public:
// If enable = true, switch to File logging (if not already logging to file).
// If enable = false, stop logging to File if currently is.
// This enables dev to scope a section which should log to File.
void logToFile(bool enable);
// Optionally, a prefix can be specified to customize log file.
void logToFile(bool enable, const std::string& fileNamePrefix = "");
// Set level for log filtering:
// 0: Errors and Warnings only
......
......@@ -112,7 +112,7 @@ void setGlobalLoggerPredicate(MessagePredicate predicate) {
XACCLogger::instance()->dumpQueue();
}
void logToFile(bool enable) { XACCLogger::instance()->logToFile(enable); }
void logToFile(bool enable, const std::string &fileNamePrefix) { XACCLogger::instance()->logToFile(enable, fileNamePrefix); }
void setLoggingLevel(int level) {
XACCLogger::instance()->setLoggingLevel(level);
......
......@@ -95,7 +95,7 @@ void addCommandLineOptions(const std::string &category,
void addCommandLineOptions(const std::map<std::string, std::string> &options);
void setGlobalLoggerPredicate(MessagePredicate predicate);
void logToFile(bool enable);
void logToFile(bool enable, const std::string &fileNamePrefix = "");
void setLoggingLevel(int level);
int getLoggingLevel();
void subscribeLoggingLevel(LoggingLevelNotification callback);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment