Commit eadbe4ef authored by Mccaskey, Alex's avatar Mccaskey, Alex
Browse files

minor cleanup



Signed-off-by: Mccaskey, Alex's avatarAlex McCaskey <mccaskeyaj@ornl.gov>
parent 8a541136
......@@ -51,11 +51,11 @@ void Initialize(int arc, char** arv) {
argc = arc;
argv = arv;
XACCLogger::instance()->info("Creating XACC ServiceRegistry");
XACCLogger::instance()->enqueueLog("Creating XACC ServiceRegistry");
// Get reference to the service registry
auto serviceRegistry = xacc::ServiceRegistry::instance();
try {
XACCLogger::instance()->info("Initializing the ServiceRegistry");
XACCLogger::instance()->enqueueLog("Initializing the ServiceRegistry");
serviceRegistry->initialize();
} catch (std::exception& e) {
XACCLogger::instance()->error("Failure initializing XACC Plugin Registry - " +
......@@ -65,16 +65,16 @@ void Initialize(int arc, char** arv) {
// Parse any user-supplied command line options
xaccCLParser->parse(argc, argv);
info("[xacc] Initializing XACC Framework.");
XACCLogger::instance()->enqueueLog("[xacc] Initializing XACC Framework.");
// Check that we have some
auto s = serviceRegistry->getServices<Compiler>().size();
auto a = serviceRegistry->getServices<Accelerator>().size();
info(
XACCLogger::instance()->enqueueLog(
"[xacc::plugins] XACC has " + std::to_string(s) + " Compiler"
+ ((s == 1 || s == 0) ? "" : "s") + " available.");
info(
XACCLogger::instance()->enqueueLog(
"[xacc::plugins] XACC has " + std::to_string(a) + " Accelerator"
+ ((s == 0 || s == 1) ? "" : "s") + " available.");
......@@ -83,8 +83,16 @@ void Initialize(int arc, char** arv) {
// We're good if we make it here, so indicate that we've been
// initialized
xacc::xaccFrameworkInitialized = true;
if (!optionExists("queue-preamble")) {
XACCLogger::instance()->dumpQueue();
}
}
void setGlobalLoggerPredicate(MessagePredicate predicate) {
XACCLogger::instance()->setGlobalLoggerPredicate(predicate);
XACCLogger::instance()->dumpQueue();
}
void info(const std::string& msg, MessagePredicate predicate) {
XACCLogger::instance()->info(msg, predicate);
......
......@@ -67,6 +67,7 @@ void addCommandLineOptions(const std::string& category, const std::map<std::stri
void addCommandLineOptions(std::shared_ptr<options_description> options);
void setGlobalLoggerPredicate(MessagePredicate predicate);
void info(const std::string& msg, MessagePredicate predicate = std::function<bool(void)>([]() {return true;}));
void debug(const std::string& msg, MessagePredicate predicate = std::function<bool(void)>([]() {return true;}));
void error(const std::string& msg, MessagePredicate predicate = std::function<bool(void)>([]() {return true;}));
......
......@@ -57,7 +57,10 @@ public:
("list-compilers", "List all available XACC Compilers")
("list-accelerators", "List all available XACC Accelerators")
("no-color", "Turn off colored logger output (blue for INFO, red for ERROR, etc.).")
("use-cout", "Use std::cout for logs instead of SPDLOG Logger.");
("use-cout", "Use std::cout for logs instead of SPDLOG Logger.")
("queue-preamble", "Pass this option to xacc::Initialize() if you would "
"like all startup messages to be queued until after a "
"global logger predicate has been passed.");
}
void addOptionsDescription(std::shared_ptr<options_description> options) {
......
......@@ -22,12 +22,15 @@ void ServiceRegistry::initialize() {
const std::string xaccLibDir = std::string(XACC_INSTALL_DIR) + std::string("/lib");
XACCLogger::instance()->info("XACC Library Directory: " + xaccLibDir);
XACCLogger::instance()->enqueueLog("XACC Library Directory: " + xaccLibDir);
for (auto &entry : boost::filesystem::directory_iterator(xaccLibDir)) {
// We want the gate and aqc bundles that come with XACC
if (boost::contains(entry.path().filename().string(),
"libxacc-quantum")) {
XACCLogger::instance()->info("Installing base plugin " + entry.path().filename().string());
auto name = entry.path().filename().string();
boost::replace_all(name,"lib","");
boost::replace_all(name,".so","");
XACCLogger::instance()->enqueueLog("Installing base plugin " + name);
context.InstallBundles(entry.path().string());
}
}
......@@ -41,7 +44,10 @@ void ServiceRegistry::initialize() {
auto p = entry.path();
if (boost::filesystem::is_directory(p)) {
for (auto& subentry : boost::filesystem::directory_iterator(p)) {
XACCLogger::instance()->info("Installing 3rd party plugin " + subentry.path().filename().string());
auto name = subentry.path().filename().string();
boost::replace_all(name,"lib","");
boost::replace_all(name,".so","");
XACCLogger::instance()->enqueueLog("Installing 3rd party plugin " + name);
context.InstallBundles(subentry.path().string());
}
}
......@@ -53,7 +59,7 @@ void ServiceRegistry::initialize() {
"There are no plugins. Install plugins to begin working with XACC.");
}
XACCLogger::instance()->info("Starting the CppUs Framework.");
XACCLogger::instance()->enqueueLog("Starting the C++ Microservices Framework.");
// Start the framework itself.
framework.Start();
......
......@@ -81,7 +81,7 @@ XACCLogger::XACCLogger() :
void XACCLogger::info(const std::string& msg, MessagePredicate predicate) {
if (useCout) {
if (predicate()) {
if (predicate() && globalPredicate()) {
if (useColor) {
std::cout << "\033[1;34m[XACC Info] " + msg + "\033[0m \n";
} else {
......@@ -89,7 +89,7 @@ void XACCLogger::info(const std::string& msg, MessagePredicate predicate) {
}
}
} else {
if (predicate()) {
if (predicate() && globalPredicate()) {
if (useColor) {
logger->info("\033[1;34m" + msg + "\033[0m");
} else {
......@@ -100,7 +100,7 @@ void XACCLogger::info(const std::string& msg, MessagePredicate predicate) {
}
void XACCLogger::debug(const std::string& msg, MessagePredicate predicate) {
if (useCout) {
if (predicate()) {
if (predicate() && globalPredicate()) {
if (useColor) {
std::cout << "\033[1;33m[XACC Debug] " + msg + "\033[0m \n";
} else {
......@@ -108,7 +108,7 @@ void XACCLogger::debug(const std::string& msg, MessagePredicate predicate) {
}
}
} else {
if (predicate()) {
if (predicate() && globalPredicate()) {
if (useColor) {
logger->info("\033[1;33m" + msg + "\033[0m");
} else {
......@@ -119,10 +119,10 @@ void XACCLogger::debug(const std::string& msg, MessagePredicate predicate) {
}
void XACCLogger::error(const std::string& msg, MessagePredicate predicate) {
if (useCout) {
if (predicate())
if (predicate() && globalPredicate())
XACCError(msg);
} else {
if (predicate()) {
if (predicate() && globalPredicate()) {
logger->error(msg);
}
}
......
......@@ -19,6 +19,7 @@
#include "RuntimeOptions.hpp"
#include "spdlog/spdlog.h"
#include <iostream>
#include <queue>
namespace xacc {
......@@ -103,49 +104,6 @@ public:
using MessagePredicate = std::function<bool(void)>;
//class LoggerImpl {
//public:
//
// virtual void info(const std::string& msg) = 0;
// virtual void error(const std::string& msg) = 0;
//
//};
//
//class SpdlogImpl : public LoggerImpl {
//
//protected:
//
// std::shared_ptr<spdlog::logger> logger;
//
// bool useColor = true;
//
//public:
//
// SpdlogImpl() : useColor(
// !RuntimeOptions::instance()->exists("no-color")) {
// logger = spdlog::stdout_logger_mt("xacc-logger");
// }
//
// virtual void info(const std::string& msg) {
// logger->info(useColor ? "\033[1;34m" + msg + "\033[0m" : msg);
// }
//
// virtual void error(const std::string& msg) {
// logger->error(useColor ? );
// }
//};
//
//class CoutImpl : public LoggerImpl {
//
//public:
//
// virtual void info(const std::string& msg) {
// }
//
// virtual void error(const std::string& msg) {
// }
//};
class XACCLogger: public Singleton<XACCLogger> {
protected:
......@@ -156,6 +114,10 @@ protected:
bool useColor = true;
MessagePredicate globalPredicate = []() { return true;};
std::queue<std::string> logQueue;
XACCLogger();
public:
......@@ -168,6 +130,17 @@ public:
return instance_;
}
void enqueueLog(const std::string log) {
logQueue.push(log);
}
void dumpQueue() {
while (!logQueue.empty()) {
info(logQueue.front());
logQueue.pop();
}
}
void setGlobalLoggerPredicate(MessagePredicate pred) {globalPredicate = pred;}
void info(const std::string& msg, MessagePredicate predicate = std::function<bool(void)>([]() {return true;}));
void debug(const std::string& msg, MessagePredicate predicate = std::function<bool(void)>([]() {return true;}));
void error(const std::string& msg, MessagePredicate predicate = std::function<bool(void)>([]() {return true;}));
......
Supports Markdown
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