MalachScript/src/Diagnostics/Logger.hpp

42 lines
1.8 KiB
C++

#ifndef MALACHSCRIPT_LOGGER_HPP
#define MALACHSCRIPT_LOGGER_HPP
#include <vector>
#include "Diagnostic.hpp"
namespace MalachScript::Diagnostics {
class Logger {
std::vector<Diagnostic> _messages;
public:
inline void Log(DiagnosticLevel level, DiagnosticType type, const ScriptTextSpan& span,
const std::vector<std::string>& formats = {}) {
_messages.emplace_back(level, type, span.GetScriptName(), span.GetSpan(), formats);
}
inline void LogTrace(DiagnosticType type, const ScriptTextSpan& span,
const std::vector<std::string>& formats = {}) {
Log(DiagnosticLevel::Trace, type, span, formats);
}
inline void LogInfo(DiagnosticType type, const ScriptTextSpan& span,
const std::vector<std::string>& formats = {}) {
Log(DiagnosticLevel::Information, type, span, formats);
}
inline void LogWarning(DiagnosticType type, const ScriptTextSpan& span,
const std::vector<std::string>& formats = {}) {
Log(DiagnosticLevel::Warning, type, span, formats);
}
inline void LogError(DiagnosticType type, const ScriptTextSpan& span,
const std::vector<std::string>& formats = {}) {
Log(DiagnosticLevel::Error, type, span, formats);
}
inline void LogCritical(DiagnosticType type, const ScriptTextSpan& span,
const std::vector<std::string>& formats = {}) {
Log(DiagnosticLevel::Critical, type, span, formats);
}
[[nodiscard]] const std::vector<Diagnostic>& GetMessages() const noexcept { return _messages; }
};
}
#endif // MALACHSCRIPT_LOGGER_HPP