mason/src/loggger.h

41 lines
876 B
C
Raw Normal View History

2023-09-01 21:39:24 +00:00
#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;
2023-09-03 00:53:36 +00:00
Logger(Severity severity = Severity::info, bool accumulate = false);
2023-09-01 21:39:24 +00:00
~Logger();
2023-09-03 00:53:36 +00:00
void log (Severity severity, const std::string& comment, bool colored = true) const;
2023-09-01 21:39:24 +00:00
std::list<Message> getLog() const;
2023-09-03 00:53:36 +00:00
void printLog(bool colored = true) const;
2023-09-01 21:39:24 +00:00
private:
2023-09-03 00:53:36 +00:00
void printMessage(const Message& message, bool colored = false) const;
private:
2023-09-27 23:30:57 +00:00
const bool accumulate;
2023-09-01 21:39:24 +00:00
const Severity currentSeverity;
mutable std::list<Message> history;
mutable std::mutex readMutex;
mutable std::mutex writeMutex;
};