2021-01-01 22:31:30 +00:00
|
|
|
#ifndef MALACHSCRIPT_LOGGER_HPP
|
|
|
|
#define MALACHSCRIPT_LOGGER_HPP
|
2020-10-04 17:38:13 +00:00
|
|
|
|
|
|
|
#include <vector>
|
|
|
|
#include "Diagnostic.hpp"
|
|
|
|
|
2020-10-05 15:45:00 +00:00
|
|
|
namespace MalachScript::Diagnostics {
|
2021-01-01 22:31:30 +00:00
|
|
|
class Logger {
|
2020-10-04 17:38:13 +00:00
|
|
|
std::vector<Diagnostic> _messages;
|
|
|
|
|
|
|
|
public:
|
2021-01-09 12:20:56 +00:00
|
|
|
inline void Log(DiagnosticLevel level, DiagnosticType type, const ScriptTextSpan& span,
|
2021-01-05 23:06:39 +00:00
|
|
|
const std::vector<std::string>& formats = {}) {
|
2021-01-09 12:20:56 +00:00
|
|
|
_messages.emplace_back(level, type, span.GetScriptName(), span.GetSpan(), formats);
|
2020-10-05 10:18:05 +00:00
|
|
|
}
|
2021-01-09 12:20:56 +00:00
|
|
|
inline void LogTrace(DiagnosticType type, const ScriptTextSpan& span,
|
|
|
|
const std::vector<std::string>& formats = {}) {
|
|
|
|
Log(DiagnosticLevel::Trace, type, span, formats);
|
2020-10-05 10:18:05 +00:00
|
|
|
}
|
2021-01-09 12:20:56 +00:00
|
|
|
inline void LogInfo(DiagnosticType type, const ScriptTextSpan& span,
|
|
|
|
const std::vector<std::string>& formats = {}) {
|
|
|
|
Log(DiagnosticLevel::Information, type, span, formats);
|
2020-10-05 10:18:05 +00:00
|
|
|
}
|
2021-01-09 12:20:56 +00:00
|
|
|
inline void LogWarning(DiagnosticType type, const ScriptTextSpan& span,
|
|
|
|
const std::vector<std::string>& formats = {}) {
|
|
|
|
Log(DiagnosticLevel::Warning, type, span, formats);
|
2020-10-05 10:18:05 +00:00
|
|
|
}
|
2021-01-09 12:20:56 +00:00
|
|
|
inline void LogError(DiagnosticType type, const ScriptTextSpan& span,
|
2021-01-05 23:25:08 +00:00
|
|
|
const std::vector<std::string>& formats = {}) {
|
2021-01-09 12:20:56 +00:00
|
|
|
Log(DiagnosticLevel::Error, type, span, formats);
|
2020-10-05 10:18:05 +00:00
|
|
|
}
|
2021-01-09 12:20:56 +00:00
|
|
|
inline void LogCritical(DiagnosticType type, const ScriptTextSpan& span,
|
|
|
|
const std::vector<std::string>& formats = {}) {
|
|
|
|
Log(DiagnosticLevel::Critical, type, span, formats);
|
2020-10-04 17:38:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
[[nodiscard]] const std::vector<Diagnostic>& GetMessages() const noexcept { return _messages; }
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2021-01-01 22:31:30 +00:00
|
|
|
#endif // MALACHSCRIPT_LOGGER_HPP
|