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(); GoggaLogger gLogger = new GoggaLogger();
// TODO: Somehow re-enable this please // Test the normal modes
// gLogger.log("Bruh\n");
gLogger.info("This is an info message"); gLogger.info("This is an info message");
gLogger.warn("This is a warning message"); gLogger.warn("This is a warning message");
gLogger.error("This is an error 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(); writeln();
} }
@ -31,14 +37,19 @@ unittest
GoggaLogger gLogger = new GoggaLogger(); GoggaLogger gLogger = new GoggaLogger();
gLogger.mode(GoggaMode.TwoKTwenty3); gLogger.mode(GoggaMode.TwoKTwenty3);
// TODO: Somehow re-enable this please // Test the normal modes
// gLogger.log("Bruh\n");
gLogger.info("This is an info message"); gLogger.info("This is an info message");
gLogger.warn("This is a warning message"); gLogger.warn("This is a warning message");
gLogger.error("This is an error 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(); writeln();
} }
@ -47,14 +58,19 @@ unittest
GoggaLogger gLogger = new GoggaLogger(); GoggaLogger gLogger = new GoggaLogger();
gLogger.mode(GoggaMode.SIMPLE); gLogger.mode(GoggaMode.SIMPLE);
// TODO: Somehow re-enable this please // Test the normal modes
// gLogger.log("Bruh\n");
gLogger.info("This is an info message"); gLogger.info("This is an info message");
gLogger.warn("This is a warning message"); gLogger.warn("This is a warning message");
gLogger.error("This is an error 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(); writeln();
} }
@ -63,21 +79,30 @@ unittest
GoggaLogger gLogger = new GoggaLogger(); GoggaLogger gLogger = new GoggaLogger();
gLogger.mode(GoggaMode.RUSTACEAN); gLogger.mode(GoggaMode.RUSTACEAN);
// TODO: Somehow re-enable this please // Test the normal modes
// gLogger.log("Bruh\n");
gLogger.info("This is an info message"); gLogger.info("This is an info message");
gLogger.warn("This is a warning message"); gLogger.warn("This is a warning message");
gLogger.error("This is an error 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(); writeln();
} }
public class GoggaLogger : Logger public class GoggaLogger : Logger
{ {
// The Gogga transformer
private GoggaTransform gTransform = new GoggaTransform(); private GoggaTransform gTransform = new GoggaTransform();
// Whether debug is enabled
private bool debugEnabled = false;
this() this()
{ {
super(gTransform); super(gTransform);
@ -242,35 +267,37 @@ public class GoggaLogger : Logger
string c4 = __MODULE__, string c5 = __FUNCTION__, string c4 = __MODULE__, string c5 = __FUNCTION__,
string c6 = __PRETTY_FUNCTION__) string c6 = __PRETTY_FUNCTION__)
{ {
/* Use the context `GoggaContext` */ /* Only debug if debugging is enabled */
GoggaContext defaultContext = new GoggaContext(); if(debugEnabled)
{
/* Use the context `GoggaContext` */
GoggaContext defaultContext = new GoggaContext();
/* Build up the line information */ /* Build up the line information */
CompilationInfo compilationInfo = CompilationInfo(c1, c2, c3, c4, c5, c6); CompilationInfo compilationInfo = CompilationInfo(c1, c2, c3, c4, c5, c6);
/* Set the line information in the context */ /* Set the line information in the context */
defaultContext.setLineInfo(compilationInfo); defaultContext.setLineInfo(compilationInfo);
/* Set the level to DEBUG */ /* Set the level to DEBUG */
defaultContext.setLevel(Level.DEBUG); defaultContext.setLevel(Level.DEBUG);
/** /**
* Grab at compile-time all arguments and generate runtime code to add them to `components` * Grab at compile-time all arguments and generate runtime code to add them to `components`
*/ */
string[] components = flatten(segments); string[] components = flatten(segments);
/* Join all `components` into a single string */ /* Join all `components` into a single string */
string messageOut = join(components, multiArgJoiner); string messageOut = join(components, multiArgJoiner);
/* Call the log */ /* Call the log */
logc(defaultContext, messageOut, c1, c2, c3, c4, c5, c6); logc(defaultContext, messageOut, c1, c2, c3, c4, c5, c6);
}
} }
/* You can also call using `dbg` */ /* You can also call using `dbg` */
public alias dbg = debug_; public alias dbg = debug_;
private bool debugEnabled = false;
// Any calls to debugPrint will actually occur // Any calls to debugPrint will actually occur
public void enableDebug() public void enableDebug()
{ {