Grindstone Game Engine v0.2.0
An open source game engine and toolkit.
Loading...
Searching...
No Matches
Logger.hpp
1#pragma once
2
3#include <fstream>
4#include <fmt/format.h>
5#include <mutex>
6
7#include "Common/Logging.hpp"
8
9namespace Grindstone::Events {
10 class Dispatcher;
11}
12
13namespace Grindstone::Logger {
14 struct LoggerState {
15 std::ofstream outputStream;
16 std::mutex mutex;
17 Events::Dispatcher* dispatcher = nullptr;
18 };
19
20 LoggerState* GetLoggerState();
21 void SetLoggerState(LoggerState*);
22
23 void Initialize(std::filesystem::path path, Grindstone::Events::Dispatcher* newDispatcher);
24 void CloseLogger();
25
26 void Print(
27 LogSeverity logSeverity,
28 LogSource logSource,
29 LogInternalType internalType,
30 const char* filename,
31 uint32_t line,
32 const char* str
33 );
34
35 template<typename... Args>
36 static void Print(
37 LogSeverity logSeverity,
38 LogSource logSource,
39 LogInternalType internalType,
40 const char* filename,
41 uint32_t line,
42 const char* fmt,
43 const Args &... args
44 ) {
45 std::string formattedString = fmt::format(fmt, args...);
46 Print(logSeverity, logSource, internalType, filename, line, formattedString.c_str());
47 }
48}
49
50#define GPRINT_TYPED(severity, source, internalType, str) Grindstone::Logger::Print(severity, source, internalType, __FILE__, __LINE__, str)
51#define GPRINT_TYPED_INFO(source, internalType, str) Grindstone::Logger::Print(Grindstone::LogSeverity::Info, source, internalType, __FILE__, __LINE__, str)
52#define GPRINT_TYPED_TRACE(source, internalType, str) Grindstone::Logger::Print(Grindstone::LogSeverity::Trace, source, internalType, __FILE__, __LINE__, str)
53#define GPRINT_TYPED_WARN(source, internalType, str) Grindstone::Logger::Print(Grindstone::LogSeverity::Warning, source, internalType, __FILE__, __LINE__, str)
54#define GPRINT_TYPED_ERROR(source, internalType, str) Grindstone::Logger::Print(Grindstone::LogSeverity::Error, source, internalType, __FILE__, __LINE__, str)
55#define GPRINT_TYPED_FATAL(source, internalType, str) Grindstone::Logger::Print(Grindstone::LogSeverity::Fatal, source, internalType, __FILE__, __LINE__, str)
56
57#define GPRINT(severity, source, str) Grindstone::Logger::Print(severity, source, Grindstone::LOG_UNSPECIFIED_INTERNAL_TYPE, __FILE__, __LINE__, str)
58#define GPRINT_INFO(source, str) Grindstone::Logger::Print(Grindstone::LogSeverity::Info, source, Grindstone::LOG_UNSPECIFIED_INTERNAL_TYPE, __FILE__, __LINE__, str)
59#define GPRINT_TRACE(source, str) Grindstone::Logger::Print(Grindstone::LogSeverity::Trace, source, Grindstone::LOG_UNSPECIFIED_INTERNAL_TYPE, __FILE__, __LINE__, str)
60#define GPRINT_WARN(source, str) Grindstone::Logger::Print(Grindstone::LogSeverity::Warning, source, Grindstone::LOG_UNSPECIFIED_INTERNAL_TYPE, __FILE__, __LINE__, str)
61#define GPRINT_ERROR(source, str) Grindstone::Logger::Print(Grindstone::LogSeverity::Error, source, Grindstone::LOG_UNSPECIFIED_INTERNAL_TYPE, __FILE__, __LINE__, str)
62#define GPRINT_FATAL(source, str) Grindstone::Logger::Print(Grindstone::LogSeverity::Fatal, source, LOG_UNSPECIFIED_INTERNAL_TYPE, __FILE__, __LINE__, str)
63
64#define GPRINT_TYPED_V(severity, source, internalType, fmt, ...) Grindstone::Logger::Print(severity, source, internalType, __FILE__, __LINE__, fmt, __VA_ARGS__)
65#define GPRINT_TYPED_INFO_V(source, internalType, fmt, ...) Grindstone::Logger::Print(Grindstone::LogSeverity::Info, source, internalType, __FILE__, __LINE__, fmt, __VA_ARGS__)
66#define GPRINT_TYPED_TRACE_V(source, internalType, fmt, ...) Grindstone::Logger::Print(Grindstone::LogSeverity::Trace, source, internalType, __FILE__, __LINE__, fmt, __VA_ARGS__)
67#define GPRINT_TYPED_WARN_V(source, internalType, fmt, ...) Grindstone::Logger::Print(Grindstone::LogSeverity::Warning, source, internalType, __FILE__, __LINE__, fmt, __VA_ARGS__)
68#define GPRINT_TYPED_ERROR_V(source, internalType, fmt, ...) Grindstone::Logger::Print(Grindstone::LogSeverity::Error, source, internalType, __FILE__, __LINE__, fmt, __VA_ARGS__)
69#define GPRINT_TYPED_FATAL_V(source, internalType, fmt, ...) Grindstone::Logger::Print(Grindstone::LogSeverity::Fatal, source, internalType, __FILE__, __LINE__, fmt, __VA_ARGS__)
70
71#define GPRINT_V(severity, source, fmt, ...) Grindstone::Logger::Print(severity, source, Grindstone::LOG_UNSPECIFIED_INTERNAL_TYPE, __FILE__, __LINE__, fmt, __VA_ARGS__)
72#define GPRINT_INFO_V(source, fmt, ...) Grindstone::Logger::Print(Grindstone::LogSeverity::Info, source, Grindstone::LOG_UNSPECIFIED_INTERNAL_TYPE, __FILE__, __LINE__, fmt, __VA_ARGS__)
73#define GPRINT_TRACE_V(source, fmt, ...) Grindstone::Logger::Print(Grindstone::LogSeverity::Trace, source, Grindstone::LOG_UNSPECIFIED_INTERNAL_TYPE, __FILE__, __LINE__, fmt, __VA_ARGS__)
74#define GPRINT_WARN_V(source, fmt, ...) Grindstone::Logger::Print(Grindstone::LogSeverity::Warning, source, Grindstone::LOG_UNSPECIFIED_INTERNAL_TYPE, __FILE__, __LINE__, fmt, __VA_ARGS__)
75#define GPRINT_ERROR_V(source, fmt, ...) Grindstone::Logger::Print(Grindstone::LogSeverity::Error, source, Grindstone::LOG_UNSPECIFIED_INTERNAL_TYPE, __FILE__, __LINE__, fmt, __VA_ARGS__)
76#define GPRINT_FATAL_V(source, fmt, ...) Grindstone::Logger::Print(Grindstone::LogSeverity::Fatal, source, LOG_UNSPECIFIED_INTERNAL_TYPE, __FILE__, __LINE__, fmt, __VA_ARGS__)
Definition Dispatcher.hpp:14
Definition Logger.cs:4
Definition Logger.hpp:14