GoggaLogger

- `debug(...)` will now only print if debugging is enabled

Unit tests

- Updated unit tests to test debugging, cleaned up
This commit is contained in:
Tristan B. Velloza Kildaire 2023-03-03 11:14:35 +02:00
parent 3c3327f769
commit d64bfb6970
1 changed files with 57 additions and 30 deletions

View File

@ -16,13 +16,19 @@ unittest
{
GoggaLogger gLogger = new GoggaLogger();
// TODO: Somehow re-enable this please
// gLogger.log("Bruh\n");
// Test the normal modes
gLogger.info("This is an info message");
gLogger.warn("This is a warning message");
gLogger.error("This is an error message");
// TODO: Add debug stuff
// We shouldn't see anything as debug is off
gLogger.dbg("This is a debug which is hidden", 1);
// Now enable debugging and you should see it
gLogger.enableDebug();
gLogger.dbg("This is a VISIBLE debug", true);
// Make space between unit tests
writeln();
}
@ -31,14 +37,19 @@ unittest
GoggaLogger gLogger = new GoggaLogger();
gLogger.mode(GoggaMode.TwoKTwenty3);
// TODO: Somehow re-enable this please
// gLogger.log("Bruh\n");
// Test the normal modes
gLogger.info("This is an info message");
gLogger.warn("This is a warning message");
gLogger.error("This is an error message");
// TODO: Add debug stuff
// We shouldn't see anything as debug is off
gLogger.dbg("This is a debug which is hidden", 1);
// Now enable debugging and you should see it
gLogger.enableDebug();
gLogger.dbg("This is a VISIBLE debug", true);
// Make space between unit tests
writeln();
}
@ -47,14 +58,19 @@ unittest
GoggaLogger gLogger = new GoggaLogger();
gLogger.mode(GoggaMode.SIMPLE);
// TODO: Somehow re-enable this please
// gLogger.log("Bruh\n");
// Test the normal modes
gLogger.info("This is an info message");
gLogger.warn("This is a warning message");
gLogger.error("This is an error message");
// TODO: Add debug stuff
// We shouldn't see anything as debug is off
gLogger.dbg("This is a debug which is hidden", 1);
// Now enable debugging and you should see it
gLogger.enableDebug();
gLogger.dbg("This is a VISIBLE debug", true);
// Make space between unit tests
writeln();
}
@ -63,21 +79,30 @@ unittest
GoggaLogger gLogger = new GoggaLogger();
gLogger.mode(GoggaMode.RUSTACEAN);
// TODO: Somehow re-enable this please
// gLogger.log("Bruh\n");
// Test the normal modes
gLogger.info("This is an info message");
gLogger.warn("This is a warning message");
gLogger.error("This is an error message");
// TODO: Add debug stuff
// We shouldn't see anything as debug is off
gLogger.dbg("This is a debug which is hidden", 1);
// Now enable debugging and you should see it
gLogger.enableDebug();
gLogger.dbg("This is a VISIBLE debug", true);
// Make space between unit tests
writeln();
}
public class GoggaLogger : Logger
{
// The Gogga transformer
private GoggaTransform gTransform = new GoggaTransform();
// Whether debug is enabled
private bool debugEnabled = false;
this()
{
super(gTransform);
@ -241,6 +266,9 @@ public class GoggaLogger : Logger
string c2 = __FILE__, ulong c3 = __LINE__,
string c4 = __MODULE__, string c5 = __FUNCTION__,
string c6 = __PRETTY_FUNCTION__)
{
/* Only debug if debugging is enabled */
if(debugEnabled)
{
/* Use the context `GoggaContext` */
GoggaContext defaultContext = new GoggaContext();
@ -265,12 +293,11 @@ public class GoggaLogger : Logger
/* Call the log */
logc(defaultContext, messageOut, c1, c2, c3, c4, c5, c6);
}
}
/* You can also call using `dbg` */
public alias dbg = debug_;
private bool debugEnabled = false;
// Any calls to debugPrint will actually occur
public void enableDebug()
{