Transform

- Make `TwoKTwenty3` the default mode
- `debugColor(string, Level)` now resets VT100 colors so it can be used individually

Logger

- Added mode selection
- Added two more unittests to test mode selection
This commit is contained in:
Tristan B. Velloza Kildaire 2023-03-02 13:49:59 +02:00
parent 7ad503825f
commit bcfcb52e1b
2 changed files with 70 additions and 3 deletions

View File

@ -7,6 +7,11 @@ import std.array : join;
import gogga.transform;
import gogga.context;
version(unittest)
{
import std.stdio : writeln;
}
unittest
{
GoggaLogger gLogger = new GoggaLogger();
@ -20,6 +25,54 @@ unittest
// TODO: Add debug stuff
}
unittest
{
GoggaLogger gLogger = new GoggaLogger();
gLogger.mode(GoggaMode.TwoKTwenty3);
// TODO: Somehow re-enable this please
// gLogger.log("Bruh\n");
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
writeln();
}
unittest
{
GoggaLogger gLogger = new GoggaLogger();
gLogger.mode(GoggaMode.SIMPLE);
// TODO: Somehow re-enable this please
// gLogger.log("Bruh\n");
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
writeln();
}
unittest
{
GoggaLogger gLogger = new GoggaLogger();
gLogger.mode(GoggaMode.RUSTACEAN);
// TODO: Somehow re-enable this please
// gLogger.log("Bruh\n");
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
writeln();
}
public class GoggaLogger : Logger
{
private GoggaTransform gTransform = new GoggaTransform();
@ -35,6 +88,11 @@ public class GoggaLogger : Logger
write(text);
}
public void mode(GoggaMode mode)
{
gTransform.setMode(mode);
}
/**
* Logs using the default context an arbitrary amount of arguments
* specifically setting the context's level to ERROR

View File

@ -2,12 +2,13 @@ module gogga.transform;
import dlog;
import gogga.context;
import std.conv : to;
// TODO: hehe easter egg TRADITIONAL, LIBERAL, UNHINGED
public enum GoggaMode
{
SIMPLE,
TwoKTwenty3,
SIMPLE,
RUSTACEAN
}
@ -39,12 +40,12 @@ public class GoggaTransform : MessageTransform
*/
if(mode == GoggaMode.SIMPLE)
{
finalOutput = cast(string)debugColor("["~to!(string)(level)~"] "~text);
finalOutput = cast(string)debugColor("["~to!(string)(level)~"] "~text, level);
}
/**
* TwoKTwenty3 is: `[<file>] (<module>:<lineNumber>) <message>`
*/
else if(mode == Gogga.TwoKTwenty3)
else if(mode == GoggaMode.TwoKTwenty3)
{
/* Module information (and status debugColoring) */
string moduleInfo = cast(string)debugColor("["~context[1]~"]", level);
@ -64,6 +65,11 @@ public class GoggaTransform : MessageTransform
return finalOutput;
}
public void setMode(GoggaMode mode)
{
this.mode = mode;
}
}
private byte[] debugColor(string text, Level level)
@ -93,6 +99,9 @@ private byte[] debugColor(string text, Level level)
/* Switch back debugColor */
messageBytes ~= cast(byte[])[27, '[', '3', '9', 'm'];
/* Reset coloring */
messageBytes ~= [27, '[', 'm'];
return messageBytes;
}