parent
e247f3813a
commit
fb3c8eb965
2 changed files with 9 additions and 11 deletions
|
|
@ -123,9 +123,6 @@ Log::Log(bool singleton)
|
||||||
assert(s_log == nullptr);
|
assert(s_log == nullptr);
|
||||||
}
|
}
|
||||||
|
|
||||||
// create mutex for multithread safe operation
|
|
||||||
m_mutex = ARCH->newMutex();
|
|
||||||
|
|
||||||
// other initalization
|
// other initalization
|
||||||
m_maxPriority = g_defaultMaxPriority;
|
m_maxPriority = g_defaultMaxPriority;
|
||||||
insert(new ConsoleLogOutputter); // NOSONAR - Adopted by `Log`
|
insert(new ConsoleLogOutputter); // NOSONAR - Adopted by `Log`
|
||||||
|
|
@ -149,7 +146,6 @@ Log::~Log()
|
||||||
for (auto index = m_alwaysOutputters.begin(); index != m_alwaysOutputters.end(); ++index) {
|
for (auto index = m_alwaysOutputters.begin(); index != m_alwaysOutputters.end(); ++index) {
|
||||||
delete *index;
|
delete *index;
|
||||||
}
|
}
|
||||||
ARCH->closeMutex(m_mutex);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Log *Log::getInstance()
|
Log *Log::getInstance()
|
||||||
|
|
@ -212,7 +208,7 @@ void Log::insert(ILogOutputter *adoptedOutputter, bool alwaysAtHead)
|
||||||
{
|
{
|
||||||
assert(adoptedOutputter != nullptr);
|
assert(adoptedOutputter != nullptr);
|
||||||
|
|
||||||
ArchMutexLock lock(m_mutex);
|
std::lock_guard<std::mutex> lock(m_mutex);
|
||||||
if (alwaysAtHead) {
|
if (alwaysAtHead) {
|
||||||
m_alwaysOutputters.push_front(adoptedOutputter);
|
m_alwaysOutputters.push_front(adoptedOutputter);
|
||||||
} else {
|
} else {
|
||||||
|
|
@ -224,14 +220,14 @@ void Log::insert(ILogOutputter *adoptedOutputter, bool alwaysAtHead)
|
||||||
|
|
||||||
void Log::remove(ILogOutputter *outputter)
|
void Log::remove(ILogOutputter *outputter)
|
||||||
{
|
{
|
||||||
ArchMutexLock lock(m_mutex);
|
std::lock_guard<std::mutex> lock(m_mutex);
|
||||||
m_outputters.remove(outputter);
|
m_outputters.remove(outputter);
|
||||||
m_alwaysOutputters.remove(outputter);
|
m_alwaysOutputters.remove(outputter);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Log::pop_front(bool alwaysAtHead)
|
void Log::pop_front(bool alwaysAtHead)
|
||||||
{
|
{
|
||||||
ArchMutexLock lock(m_mutex);
|
std::lock_guard<std::mutex> lock(m_mutex);
|
||||||
OutputterList *list = alwaysAtHead ? &m_alwaysOutputters : &m_outputters;
|
OutputterList *list = alwaysAtHead ? &m_alwaysOutputters : &m_outputters;
|
||||||
if (!list->empty()) {
|
if (!list->empty()) {
|
||||||
delete list->front();
|
delete list->front();
|
||||||
|
|
@ -255,13 +251,13 @@ bool Log::setFilter(const char *maxPriority)
|
||||||
|
|
||||||
void Log::setFilter(int maxPriority)
|
void Log::setFilter(int maxPriority)
|
||||||
{
|
{
|
||||||
ArchMutexLock lock(m_mutex);
|
std::lock_guard<std::mutex> lock(m_mutex);
|
||||||
m_maxPriority = maxPriority;
|
m_maxPriority = maxPriority;
|
||||||
}
|
}
|
||||||
|
|
||||||
int Log::getFilter() const
|
int Log::getFilter() const
|
||||||
{
|
{
|
||||||
ArchMutexLock lock(m_mutex);
|
std::lock_guard<std::mutex> lock(m_mutex);
|
||||||
return m_maxPriority;
|
return m_maxPriority;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -272,7 +268,7 @@ void Log::output(ELevel priority, const char *msg)
|
||||||
if (!msg)
|
if (!msg)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
ArchMutexLock lock(m_mutex);
|
std::lock_guard<std::mutex> lock(m_mutex);
|
||||||
|
|
||||||
OutputterList::const_iterator i;
|
OutputterList::const_iterator i;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -11,6 +11,8 @@
|
||||||
#include "arch/IArchMultithread.h"
|
#include "arch/IArchMultithread.h"
|
||||||
#include "common/Common.h"
|
#include "common/Common.h"
|
||||||
|
|
||||||
|
#include <mutex>
|
||||||
|
|
||||||
#define CLOG (Log::getInstance())
|
#define CLOG (Log::getInstance())
|
||||||
#define BYE "\nTry `%s --help' for more information."
|
#define BYE "\nTry `%s --help' for more information."
|
||||||
|
|
||||||
|
|
@ -128,7 +130,7 @@ private:
|
||||||
|
|
||||||
static Log *s_log;
|
static Log *s_log;
|
||||||
|
|
||||||
ArchMutex m_mutex;
|
mutable std::mutex m_mutex;
|
||||||
OutputterList m_outputters;
|
OutputterList m_outputters;
|
||||||
OutputterList m_alwaysOutputters;
|
OutputterList m_alwaysOutputters;
|
||||||
int m_maxPriority;
|
int m_maxPriority;
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue