Paul Zinselmeyer
ba8e969470
All checks were successful
Latex Build / build-latex (Assignment 4 - Protokollsicherheit (Praxis)) (push) Successful in 1m2s
Latex Build / build-latex (Assignment 5 - Software Security - Teil 1) (push) Successful in 1m3s
Latex Build / build-latex (Assignment 6 - Software Security - Teil 2) (push) Successful in 1m0s
Latex Build / build-latex (Assignment 4 - Protokollsicherheit (Praxis)) (pull_request) Successful in 30s
Latex Build / build-latex (Assignment 5 - Software Security - Teil 1) (pull_request) Successful in 10s
Latex Build / build-latex (Assignment 6 - Software Security - Teil 2) (pull_request) Successful in 8s
85 lines
1.6 KiB
C++
85 lines
1.6 KiB
C++
#include "LogBase.h"
|
|
#include <iostream>
|
|
|
|
namespace util {
|
|
|
|
LogBase* LogBase::instance = NULL;
|
|
|
|
LogBase* LogBase::Inst() {
|
|
if (instance == NULL) {
|
|
instance = new LogBase();
|
|
}
|
|
|
|
return instance;
|
|
}
|
|
|
|
|
|
LogBase::LogBase() {
|
|
m_enabled[log::verbose] = false;
|
|
m_enabled[log::info] = true;
|
|
m_enabled[log::warning] = true;
|
|
m_enabled[log::error] = true;
|
|
m_enabled[log::timer] = false;
|
|
|
|
this->appender = new log4cpp::OstreamAppender("console", &std::cout);
|
|
this->appender->setLayout(new log4cpp::BasicLayout());
|
|
|
|
root.setPriority(log4cpp::Priority::INFO);
|
|
root.addAppender(this->appender);
|
|
}
|
|
|
|
|
|
LogBase::~LogBase() {}
|
|
|
|
|
|
void LogBase::Log(const log::Fmt& msg, log::Severity s) {
|
|
if (IsEnabled(s) && !IsEnabled(log::timer)) {
|
|
switch (s) {
|
|
case log::info:
|
|
root.info(msg.str());
|
|
break;
|
|
case log::error:
|
|
root.error(msg.str());
|
|
break;
|
|
case log::warning:
|
|
root.warn(msg.str());
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
bool LogBase::Enable(log::Severity s, bool enable) {
|
|
bool prev = m_enabled[s];
|
|
m_enabled[s] = enable;
|
|
|
|
return prev;
|
|
}
|
|
|
|
|
|
void LogBase::DisableAll(bool b) {
|
|
m_enabled[log::verbose] = b;
|
|
m_enabled[log::info] = b;
|
|
m_enabled[log::warning] = b;
|
|
m_enabled[log::error] = b;
|
|
m_enabled[log::timer] = b;
|
|
}
|
|
|
|
|
|
bool LogBase::IsEnabled( log::Severity s ) const {
|
|
return m_enabled[s];
|
|
}
|
|
|
|
|
|
void Log(const string& str, log::Severity s) {
|
|
LogBase::Inst()->Log(log::Fmt(str), s);
|
|
}
|
|
|
|
|
|
void DisableAllLogs(bool b) {
|
|
LogBase::Inst()->DisableAll(b);
|
|
}
|
|
|
|
|
|
|
|
}
|