mason/src/loggger.h
2023-09-27 20:30:57 -03:00

41 lines
876 B
C++

#pragma once
#include <list>
#include <string>
#include <mutex>
#include <array>
#include <string_view>
#include <iostream>
class Logger {
public:
enum class Severity {
debug,
info,
minor,
major,
warning,
error,
fatal
};
typedef std::pair<Severity, std::string> Message;
Logger(Severity severity = Severity::info, bool accumulate = false);
~Logger();
void log (Severity severity, const std::string& comment, bool colored = true) const;
std::list<Message> getLog() const;
void printLog(bool colored = true) const;
private:
void printMessage(const Message& message, bool colored = false) const;
private:
const bool accumulate;
const Severity currentSeverity;
mutable std::list<Message> history;
mutable std::mutex readMutex;
mutable std::mutex writeMutex;
};