1
0
mirror of https://github.com/binary-kitchen/doorlockd synced 2024-12-22 18:34:25 +01:00

removed usings from logger.cpp

This commit is contained in:
Ralf Ramsauer 2015-10-02 17:27:51 +02:00
parent 54f22393a4
commit 77b3c82916

View File

@ -15,15 +15,6 @@
#include "config.h" #include "config.h"
#include "logger.h" #include "logger.h"
using std::map;
using std::string;
using std::mutex;
using std::lock_guard;
using std::move;
using std::cerr;
using std::endl;
#ifdef USE_COLORIZED_LOGS #ifdef USE_COLORIZED_LOGS
#ifdef _WIN32 // If Windows, Use Windows Terminal coloring #ifdef _WIN32 // If Windows, Use Windows Terminal coloring
const static map<LogLevel, WORD> colorAttribute = { const static map<LogLevel, WORD> colorAttribute = {
@ -35,7 +26,7 @@ const static map<LogLevel, WORD> colorAttribute = {
{LogLevel::debug2, FOREGROUND_BLUE | FOREGROUND_RED }, {LogLevel::debug2, FOREGROUND_BLUE | FOREGROUND_RED },
}; };
#else // Use ANSI Escape sequences #else // Use ANSI Escape sequences
const static map<LogLevel, string> prefix_ansicolor = { const static std::map<LogLevel, std::string> prefix_ansicolor = {
{LogLevel::error, "\x1b[1m\x1b[31m" }, {LogLevel::error, "\x1b[1m\x1b[31m" },
{LogLevel::warning, "\x1b[1m\x1b[33m" }, {LogLevel::warning, "\x1b[1m\x1b[33m" },
{LogLevel::notice, "\x1b[1m\x1b[34m" }, {LogLevel::notice, "\x1b[1m\x1b[34m" },
@ -44,11 +35,11 @@ const static map<LogLevel, string> prefix_ansicolor = {
{LogLevel::debug2, "\x1b[1m\x1b[36m" }, {LogLevel::debug2, "\x1b[1m\x1b[36m" },
}; };
const static string suffix_ansireset = "\x1b[0m"; const static std::string suffix_ansireset = "\x1b[0m";
#endif #endif
#endif #endif
const static map<LogLevel, string> logLevel = { const static std::map<LogLevel, std::string> logLevel = {
{LogLevel::error, "ERROR " }, {LogLevel::error, "ERROR " },
{LogLevel::warning, "WARNING" }, {LogLevel::warning, "WARNING" },
{LogLevel::notice, "NOTICE " }, {LogLevel::notice, "NOTICE " },
@ -75,7 +66,8 @@ Logger &Logger::get()
return l; return l;
} }
void Logger::operator ()(const std::string &message, const LogLevel level) void Logger::operator ()(const std::string &message,
const LogLevel level)
{ {
if(level > _level) if(level > _level)
{ {
@ -103,15 +95,17 @@ void Logger::operator ()(const std::string &message, const LogLevel level)
// Critical section // Critical section
{ {
lock_guard<mutex> lock(_ostreamMutex); std::lock_guard<std::mutex> lock(_ostreamMutex);
#if defined(USE_COLORIZED_LOGS) && !defined(_WIN32) #if defined(USE_COLORIZED_LOGS) && !defined(_WIN32)
if (_consoleActive) { if (_consoleActive) {
cerr << prefix.str() << message << suffix_ansireset << endl; std::cerr << prefix.str() << message
cerr.flush(); << suffix_ansireset << std::endl;
std::cerr.flush();
} }
if (_logFileActive && _logFile.is_open()) { if (_logFileActive && _logFile.is_open()) {
_logFile << prefix.str() << message << suffix_ansireset << endl; _logFile << prefix.str() << message
<< suffix_ansireset << std::endl;
} }
#elif defined(USE_COLORIZED_LOGS) && defined(_WIN32) #elif defined(USE_COLORIZED_LOGS) && defined(_WIN32)
@ -127,27 +121,27 @@ void Logger::operator ()(const std::string &message, const LogLevel level)
// We need to flush the stream buffers into the console before each // We need to flush the stream buffers into the console before each
// SetConsoleTextAttribute call lest it affect the text that is already // SetConsoleTextAttribute call lest it affect the text that is already
// printed but has not yet reached the console. // printed but has not yet reached the console.
cerr.flush(); std::cerr.flush();
SetConsoleTextAttribute(stdout_handle, SetConsoleTextAttribute(stdout_handle,
colorAttribute.at(level) | FOREGROUND_INTENSITY); colorAttribute.at(level) | FOREGROUND_INTENSITY);
cerr << prefix.str() << message << endl; std::cerr << prefix.str() << message << std::endl;
cerr.flush(); std::cerr.flush();
// Restores the text color. // Restores the text color.
SetConsoleTextAttribute(stdout_handle, old_color_attrs); SetConsoleTextAttribute(stdout_handle, old_color_attrs);
} }
if (_logFileActive && _logFile.is_open()) { if (_logFileActive && _logFile.is_open()) {
_logFile << prefix.str() << message << endl; _logFile << prefix.str() << message << std::endl;
} }
#else #else
if (_consoleActive) { if (_consoleActive) {
cerr << prefix.str() << message << endl; std::cerr << prefix.str() << message << std::endl;
cerr.flush(); std::cerr.flush();
} }
if (_logFileActive && _logFile.is_open()) { if (_logFileActive && _logFile.is_open()) {
_logFile << prefix.str() << message << endl; _logFile << prefix.str() << message << std::endl;
} }
#endif #endif
} }
@ -186,7 +180,7 @@ void Logger::operator ()(const LogLevel level, const char* format, ...)
vsnprintf(message, size, format, argp); vsnprintf(message, size, format, argp);
va_end(argp); va_end(argp);
(*this)(string(message), level); (*this)(std::string(message), level);
free(message); free(message);
} else { } else {
@ -212,7 +206,7 @@ bool Logger::console() const
void Logger::console(const bool active) void Logger::console(const bool active)
{ {
lock_guard<mutex> lock(_ostreamMutex); std::lock_guard<std::mutex> lock(_ostreamMutex);
_consoleActive = active; _consoleActive = active;
} }
@ -223,7 +217,7 @@ bool Logger::logFile() const
void Logger::logFile(const bool active) void Logger::logFile(const bool active)
{ {
lock_guard<mutex> lock(_ostreamMutex); std::lock_guard<std::mutex> lock(_ostreamMutex);
_logFileActive = active; _logFileActive = active;
} }