1
0
Fork 0
mirror of https://github.com/polybar/polybar.git synced 2024-11-25 13:55:47 -05:00

logger: Output INFO messages as default

This commit is contained in:
Michael Carlberg 2016-06-20 14:01:20 +02:00
parent 4b2d2fc986
commit ff7e15db88
4 changed files with 25 additions and 22 deletions

View file

@ -18,14 +18,12 @@ struct RegistryModuleEntry
class Registry class Registry
{ {
// Stopped and no loaded modules const int STAGE_1 = 1; // Stopped and no loaded modules
const int STAGE_1 = 1; const int STAGE_2 = 2; // Modules loaded but waiting for initial broadcast
// Modules loaded but waiting for initial broadcast const int STAGE_3 = 3; // Running
const int STAGE_2 = 2; const int STAGE_4 = 4; // Unloading modules
// Running
const int STAGE_3 = 3; std::shared_ptr<Logger> logger;
// Unloading modules
const int STAGE_4 = 4;
concurrency::Atomic<int> stage; concurrency::Atomic<int> stage;

View file

@ -38,7 +38,7 @@ class Logger
{ {
std::mutex mtx; std::mutex mtx;
int level = LogLevel::LEVEL_ERROR | LogLevel::LEVEL_WARNING; int level = LogLevel::LEVEL_ERROR | LogLevel::LEVEL_WARNING | LogLevel::LEVEL_INFO;
int fd = LOGGER_FD; int fd = LOGGER_FD;
public: public:

View file

@ -37,7 +37,7 @@ void EventLoop::start()
if (this->state() == STATE_STARTED) if (this->state() == STATE_STARTED)
return; return;
this->logger->info("Starting event loop..."); this->logger->debug("Starting event loop...");
this->bar->load(); this->bar->load();
this->registry->load(); this->registry->load();
@ -46,6 +46,8 @@ void EventLoop::start()
this->t_write = std::thread(&EventLoop::loop_write, this); this->t_write = std::thread(&EventLoop::loop_write, this);
this->t_read = std::thread(&EventLoop::loop_read, this); this->t_read = std::thread(&EventLoop::loop_read, this);
this->logger->debug("Event loop started...");
} }
void EventLoop::stop() void EventLoop::stop()
@ -53,6 +55,8 @@ void EventLoop::stop()
if (this->state() == STATE_STOPPED) if (this->state() == STATE_STOPPED)
return; return;
this->logger->debug("Stopping event loop...");
this->state = STATE_STOPPED; this->state = STATE_STOPPED;
// break the input read block - totally how it's meant to be done! // break the input read block - totally how it's meant to be done!
@ -62,7 +66,8 @@ void EventLoop::stop()
} }
this->registry->unload(); this->registry->unload();
this->logger->info("Event loop stopped...");
this->logger->debug("Event loop stopped...");
} }
void EventLoop::wait() void EventLoop::wait()
@ -225,7 +230,7 @@ void EventLoop::write_stdout()
void EventLoop::cleanup(int timeout_ms) void EventLoop::cleanup(int timeout_ms)
{ {
log_info("Cleaning up..."); this->logger->debug("Cleaning up...");
std::atomic<bool> t_read_joined(false); std::atomic<bool> t_read_joined(false);
std::atomic<bool> t_write_joined(false); std::atomic<bool> t_write_joined(false);

View file

@ -10,9 +10,9 @@ std::shared_ptr<Registry> &get_registry()
return registry; return registry;
} }
Registry::Registry() Registry::Registry() : logger(get_logger())
{ {
get_logger()->debug("Entering STAGE 1"); this->logger->debug("Entering STAGE 1");
this->stage = STAGE_1; this->stage = STAGE_1;
} }
@ -22,7 +22,7 @@ bool Registry::ready()
if (stage == STAGE_2) if (stage == STAGE_2)
for (auto &&entry : this->modules) for (auto &&entry : this->modules)
if (!entry->warmedup) get_logger()->debug("Waiting for: "+ entry->module->name()); if (!entry->warmedup) this->logger->debug("Waiting for: "+ entry->module->name());
return stage == STAGE_3; return stage == STAGE_3;
} }
@ -38,11 +38,11 @@ void Registry::load()
if (this->stage() != STAGE_1) if (this->stage() != STAGE_1)
return; return;
get_logger()->debug("Entering STAGE 2"); this->logger->debug("Entering STAGE 2");
this->stage = STAGE_2; this->stage = STAGE_2;
get_logger()->debug("Loading modules"); this->logger->debug("Loading modules");
for (auto &&entry : this->modules) { for (auto &&entry : this->modules) {
std::lock_guard<std::mutex> wait_lck(this->wait_mtx); std::lock_guard<std::mutex> wait_lck(this->wait_mtx);
@ -56,11 +56,11 @@ void Registry::unload()
if (this->stage() != STAGE_3) if (this->stage() != STAGE_3)
return; return;
get_logger()->debug("Entering STAGE 4"); this->logger->debug("Entering STAGE 4");
this->stage = STAGE_4; this->stage = STAGE_4;
get_logger()->debug("Unloading modules"); this->logger->debug("Unloading modules");
// Release wait lock // Release wait lock
{ {
@ -95,8 +95,8 @@ bool Registry::wait()
continue; continue;
} }
get_logger()->info("Received initial broadcast from all modules"); this->logger->debug("Received initial broadcast from all modules");
get_logger()->debug("Entering STAGE 3"); this->logger->debug("Entering STAGE 3");
this->stage = STAGE_3; this->stage = STAGE_3;
break; break;
@ -136,7 +136,7 @@ void Registry::notify(const std::string& module_name)
mod_entry->module->refresh(); mod_entry->module->refresh();
} catch (Exception &e) { } catch (Exception &e) {
log_trace("Exception occurred in runner thread for: "+ module_name); log_trace("Exception occurred in runner thread for: "+ module_name);
get_logger()->error(e.what()); this->logger->error(e.what());
} }