MalachScript/src/Diagnostics/Logger.hpp

38 lines
1.6 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, std::u8string_view scriptName, TextSpan span,
const std::vector<std::string>& formats = {}) {
_messages.emplace_back(level, type, scriptName, span, formats);
}
inline void LogTrace(DiagnosticType type, std::u8string_view scriptName, TextSpan span) {
Log(DiagnosticLevel::Trace, type, scriptName, span);
}
inline void LogInfo(DiagnosticType type, std::u8string_view scriptName, TextSpan span) {
Log(DiagnosticLevel::Information, type, scriptName, span);
}
inline void LogWarning(DiagnosticType type, std::u8string_view scriptName, TextSpan span) {
Log(DiagnosticLevel::Warning, type, scriptName, span);
}
inline void LogError(DiagnosticType type, std::u8string_view scriptName, TextSpan span,
const std::vector<std::string>& formats = {}) {
Log(DiagnosticLevel::Error, type, scriptName, span, formats);
}
inline void LogCritical(DiagnosticType type, std::u8string_view scriptName, TextSpan span) {
Log(DiagnosticLevel::Critical, type, scriptName, span);
}
[[nodiscard]] const std::vector<Diagnostic>& GetMessages() const noexcept { return _messages; }
};
}
#endif // MALACHSCRIPT_LOGGER_HPP