From f3c5ac3d602abf4ee08945381ba64fdcd433a670 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Simon=20L=C3=BCbe=C3=9F?= Date: Wed, 30 Dec 2020 14:22:51 +0100 Subject: [PATCH] Added Assert to Logger --- GlitchLog/src/DebugLogger.bf | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/GlitchLog/src/DebugLogger.bf b/GlitchLog/src/DebugLogger.bf index 30d92c4..95c5b06 100644 --- a/GlitchLog/src/DebugLogger.bf +++ b/GlitchLog/src/DebugLogger.bf @@ -23,6 +23,8 @@ namespace GlitchLog public abstract void Error(StringView format, params Object[] args); public abstract void Critical(StringView format, params Object[] args); + public abstract void Assert(bool condition, String error = Compiler.CallerExpression[0], String filePath = Compiler.CallerFilePath, int line = Compiler.CallerLineNum); + public abstract void Log(LogLevel level, StringView format, params Object[] args); } @@ -100,6 +102,16 @@ namespace GlitchLog InternalLog(level, format, params args); } + public override void Assert(bool condition, String error = Compiler.CallerExpression[0], String filePath = Compiler.CallerFilePath, int line = Compiler.CallerLineNum) + { + if (!condition) + { + String failStr = scope .()..AppendF("Assert failed: {} at line {} in {}", error, line, filePath); + InternalLog(.Critical, failStr); + Internal.FatalError(failStr, 1); + } + } + private void InternalLog(LogLevel level, StringView format, params Object[] args) { if(_logLevel > level)