Commit 892fa496 authored by Daniel Krebs's avatar Daniel Krebs

lib/log: purge remaining of old logger

parent b21a7d2b
#pragma once
#include <iostream>
#include <string>
#define SPDLOG_LEVEL_NAMES { "trace", "debug", "info ", "warn ", "error", "crit ", "off " }
......@@ -22,109 +21,3 @@ inline SpdLogger loggerGetOrCreate(const std::string& logger_name)
}
return logger;
}
class LoggerIndent;
class Logger {
friend LoggerIndent;
public:
enum class LogLevel : int {
Debug,
Info,
Warning,
Error,
Disabled
};
class LoggerNewline {
public:
LoggerNewline(bool enabled = true) : enabled(enabled) {}
~LoggerNewline() {
if(enabled)
std::cout << std::endl;
}
template <typename T>
LoggerNewline& operator<< (T const& value) {
if(enabled)
std::cout << value;
return *this;
}
bool enabled;
};
class Indenter {
public:
Indenter(Logger* l) : logger(l)
{ logger->increaseIndention(); }
~Indenter()
{ logger->decreaseIndention(); }
private:
Logger* logger;
};
Logger(LogLevel level, std::string prefix = "") : level(level), prefix(prefix) {}
Indenter indent()
{ return Indenter(this); }
static std::string
getPadding()
{
std::string out = "";
for(int i = 0; i < depthCurrent; i++) out.append("\u2551 ");
return out;
}
template <typename T>
LoggerNewline operator<< (T const& value) {
if(level >= global_level) {
if(depth > depthCurrent) {
std::cout << Logger::getPadding() << "\u255f\u2500\u2556" << std::endl;
depthCurrent++;
}
std::cout << Logger::getPadding() << "\u255f " << prefix << value;
return LoggerNewline();
} else {
return LoggerNewline(false);
}
}
void
increaseIndention()
{
depth++;
}
void
decreaseIndention()
{
if(depth == depthCurrent)
std::cout << Logger::getPadding() << std::endl;
depthCurrent = --depth;
}
static
void
setLogLevel(LogLevel level)
{ global_level = level; }
private:
LogLevel level;
std::string prefix;
static int depth;
static LogLevel global_level;
static int depthCurrent;
};
extern Logger cpp_debug;
extern Logger cpp_info;
extern Logger cpp_warn;
extern Logger cpp_error;
......@@ -33,7 +33,6 @@ set(SOURCES
log.c
log_config.c
log_helper.c
log.cpp
)
include(FindPkgConfig)
......
#include "log.hpp"
#include "utils.h"
int Logger::depth;
int Logger::depthCurrent;
Logger::LogLevel Logger::global_level = Logger::LogLevel::Info;
Logger cpp_debug(Logger::LogLevel::Debug, "" CLR_BLU(" Debug ") "| ");
Logger cpp_info(Logger::LogLevel::Info);
Logger cpp_warn(Logger::LogLevel::Warning, "" CLR_YEL("Warning") "| ");
Logger cpp_error(Logger::LogLevel::Error, "" CLR_RED(" Error ") "| ");
void test()
{
cpp_debug << "Hello";
{
Logger::Indenter indent = cpp_debug.indent();
cpp_debug << "indented";
{
Logger::Indenter indent = cpp_debug.indent();
cpp_debug << "indented";
}
}
cpp_debug << "and root again";
}
Markdown is supported
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