diff --git a/Include/Pipe.h b/Include/Pipe.h index 0a0d9b61..039fe2bd 100644 --- a/Include/Pipe.h +++ b/Include/Pipe.h @@ -8,6 +8,6 @@ namespace p { - PIPE_API void Initialize(StringView logPath = {}); + PIPE_API void Initialize(Logger* logger = nullptr); PIPE_API void Shutdown(); }; // namespace p diff --git a/Include/Pipe/Core/Log.h b/Include/Pipe/Core/Log.h index 97a50d55..08eeb089 100644 --- a/Include/Pipe/Core/Log.h +++ b/Include/Pipe/Core/Log.h @@ -9,7 +9,14 @@ namespace p { - PIPE_API void InitLog(StringView logPath = {}); + struct Logger + { + std::function infoCallback; + std::function warningCallback; + std::function errorCallback; + }; + + PIPE_API void InitLog(Logger* logger = nullptr); PIPE_API void ShutdownLog(); PIPE_API void Info(StringView msg); diff --git a/Include/PipeReflect.h b/Include/PipeReflect.h index 2c02ef67..1fc3278b 100644 --- a/Include/PipeReflect.h +++ b/Include/PipeReflect.h @@ -958,7 +958,6 @@ namespace p { return TPtr{value}; } - TPtr ptr{value}; return Cast(ptr); } diff --git a/Src/Core/Log.cpp b/Src/Core/Log.cpp index 26241468..fe734f42 100644 --- a/Src/Core/Log.cpp +++ b/Src/Core/Log.cpp @@ -11,34 +11,65 @@ namespace p { - void InitLog(StringView logPath) {} + // clang-format off + const Logger defaultLogger = Logger{ + .infoCallback = [](StringView msg) { + String text; + auto now = DateTime::Now(); + now.ToString("[%Y/%m/%d %H:%M:%S]", text); + Strings::FormatTo(text, "[Info] {}\n", msg); + std::cout << text; + }, + .warningCallback = [](StringView msg) { + String text; + auto now = DateTime::Now(); + now.ToString("[%Y/%m/%d %H:%M:%S]", text); + Strings::FormatTo(text, "[Warning] {}\n", msg); + std::cout << text; + }, + .errorCallback = [](StringView msg) { + String text; + auto now = DateTime::Now(); + now.ToString("[%Y/%m/%d %H:%M:%S]", text); + Strings::FormatTo(text, "[Error] {}\n", msg); + std::cout << text; + } + }; + // clang-format on - void ShutdownLog() {} + const Logger* globalLogger = nullptr; + + void InitLog(Logger* logger) + { + globalLogger = logger ? logger : &defaultLogger; + } + + void ShutdownLog() + { + globalLogger = nullptr; + } void Info(StringView msg) { - String text; - auto now = DateTime::Now(); - now.ToString("[%Y/%m/%d %H:%M:%S]", text); - Strings::FormatTo(text, "[Info] {}", msg); - std::cout << text << std::endl; + if (globalLogger) + { + globalLogger->infoCallback(msg); + } } void Warning(StringView msg) { - String text; - auto now = DateTime::Now(); - now.ToString("[%Y/%m/%d %H:%M:%S]", text); - Strings::FormatTo(text, "[Warning] {}", msg); - std::cout << text << std::endl; + if (globalLogger) + { + globalLogger->warningCallback(msg); + } } void Error(StringView msg) { - String text; - auto now = DateTime::Now(); - now.ToString("[%Y/%m/%d %H:%M:%S]", text); - Strings::FormatTo(text, "[Error] {}", msg); - std::cout << text << std::endl; + if (globalLogger) + { + globalLogger->errorCallback(msg); + } } } // namespace p diff --git a/Src/Pipe.cpp b/Src/Pipe.cpp index da56a142..ad3fb019 100644 --- a/Src/Pipe.cpp +++ b/Src/Pipe.cpp @@ -13,11 +13,11 @@ namespace p { - void Initialize(StringView logPath) + void Initialize(Logger* logger) { InitializeMemory(); InitializeReflect(); - InitLog(logPath); + InitLog(logger); } void Shutdown() diff --git a/Tests/Reflection/TypeName.spec.cpp b/Tests/Reflection/TypeName.spec.cpp index 13409e45..470f3c23 100644 --- a/Tests/Reflection/TypeName.spec.cpp +++ b/Tests/Reflection/TypeName.spec.cpp @@ -38,7 +38,7 @@ go_bandit([]() { AssertThat(GetTypeName(), Equals("i16")); AssertThat(GetTypeName(), Equals("i32")); AssertThat(GetTypeName(), Equals("i64")); - AssertThat(GetTypeName(), Equals("TChar")); + AssertThat(GetTypeName(), Equals("char")); AssertThat(GetTypeName(), Equals("StringView")); AssertThat(GetTypeName(), Equals("String")); });