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);
@ -242,35 +267,37 @@ public class GoggaLogger : Logger
string c4 = __MODULE__, string c5 = __FUNCTION__,
string c6 = __PRETTY_FUNCTION__)
{
/* Use the context `GoggaContext` */
GoggaContext defaultContext = new GoggaContext();
/* Only debug if debugging is enabled */
if(debugEnabled)
{
/* Use the context `GoggaContext` */
GoggaContext defaultContext = new GoggaContext();
/* Build up the line information */
CompilationInfo compilationInfo = CompilationInfo(c1, c2, c3, c4, c5, c6);
/* Build up the line information */
CompilationInfo compilationInfo = CompilationInfo(c1, c2, c3, c4, c5, c6);
/* Set the line information in the context */
defaultContext.setLineInfo(compilationInfo);
/* Set the line information in the context */
defaultContext.setLineInfo(compilationInfo);
/* Set the level to DEBUG */
defaultContext.setLevel(Level.DEBUG);
/* Set the level to DEBUG */
defaultContext.setLevel(Level.DEBUG);
/**
* Grab at compile-time all arguments and generate runtime code to add them to `components`
*/
string[] components = flatten(segments);
/**
* Grab at compile-time all arguments and generate runtime code to add them to `components`
*/
string[] components = flatten(segments);
/* Join all `components` into a single string */
string messageOut = join(components, multiArgJoiner);
/* Join all `components` into a single string */
string messageOut = join(components, multiArgJoiner);
/* Call the log */
logc(defaultContext, messageOut, c1, c2, c3, c4, c5, c6);
/* 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()
{