summaryrefslogtreecommitdiff
path: root/deimos/core/log.h
diff options
context:
space:
mode:
Diffstat (limited to 'deimos/core/log.h')
-rw-r--r--deimos/core/log.h71
1 files changed, 71 insertions, 0 deletions
diff --git a/deimos/core/log.h b/deimos/core/log.h
new file mode 100644
index 0000000..cf92391
--- /dev/null
+++ b/deimos/core/log.h
@@ -0,0 +1,71 @@
+#pragma once
+
+#include "deimos/core/base.h"
+#include "deimos/core/id_name.h"
+#include "deimos/core/format.h"
+
+namespace deimos
+{
+
+enum class LogSeverity
+{
+ kInfo,
+ kDebug,
+ kError,
+};
+
+class ILogger
+{
+public:
+ ILogger() = default;
+ deimos_NO_COPY_MOVE(ILogger);
+ virtual ~ILogger() = default;
+
+ // @Todo Use string view
+ virtual void Log(LogSeverity, const SourceLocation&, Span<const char>) = 0;
+};
+
+// Just a helper to pass a SourceLocation without having to write {} to logging functions.
+struct LogSourceLocation
+{
+ gsl::czstring fmt;
+ SourceLocation source_location;
+
+ // NOLINTNEXTLINE(*-explicit-conversions)
+ LogSourceLocation(gsl::czstring fmt_, const SourceLocation& source_location_ = {}) :
+ fmt{fmt_}, source_location{source_location_}
+ {}
+};
+
+class LogApi
+{
+public:
+ static constexpr IdName kApiName{"deimos::LogApi"};
+
+ LogApi() = default;
+ deimos_NO_COPY_MOVE(LogApi);
+ virtual ~LogApi() = default;
+
+ virtual void LogVa(LogSeverity, const SourceLocation&, gsl::czstring msg, Span<const FormatArg>) = 0;
+
+ template<Formattable... Args>
+ void LogInfo(const LogSourceLocation& fmt_source_location, Args&&... args)
+ {
+ LogVa(LogSeverity::kInfo, fmt_source_location.source_location, fmt_source_location.fmt, { FormatArg(std::forward<Args>(args))... });
+ }
+
+ template<Formattable... Args>
+ void LogDebug(const LogSourceLocation& fmt_source_location, Args&&... args)
+ {
+ LogVa(LogSeverity::kDebug, fmt_source_location.source_location, fmt_source_location.fmt, { FormatArg(std::forward<Args>(args))... });
+ }
+
+ template<Formattable... Args>
+ void LogError(const LogSourceLocation& fmt_source_location, Args&&... args)
+ {
+ LogVa(LogSeverity::kError, fmt_source_location.source_location, fmt_source_location.fmt, { FormatArg(std::forward<Args>(args))... });
+ }
+};
+
+} // namespace deimos
+