mirror of https://github.com/deavmi/gogga.git
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:
parent
7ad503825f
commit
bcfcb52e1b
|
@ -7,6 +7,11 @@ import std.array : join;
|
||||||
import gogga.transform;
|
import gogga.transform;
|
||||||
import gogga.context;
|
import gogga.context;
|
||||||
|
|
||||||
|
version(unittest)
|
||||||
|
{
|
||||||
|
import std.stdio : writeln;
|
||||||
|
}
|
||||||
|
|
||||||
unittest
|
unittest
|
||||||
{
|
{
|
||||||
GoggaLogger gLogger = new GoggaLogger();
|
GoggaLogger gLogger = new GoggaLogger();
|
||||||
|
@ -20,6 +25,54 @@ unittest
|
||||||
// TODO: Add debug stuff
|
// 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
|
public class GoggaLogger : Logger
|
||||||
{
|
{
|
||||||
private GoggaTransform gTransform = new GoggaTransform();
|
private GoggaTransform gTransform = new GoggaTransform();
|
||||||
|
@ -35,6 +88,11 @@ public class GoggaLogger : Logger
|
||||||
write(text);
|
write(text);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void mode(GoggaMode mode)
|
||||||
|
{
|
||||||
|
gTransform.setMode(mode);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Logs using the default context an arbitrary amount of arguments
|
* Logs using the default context an arbitrary amount of arguments
|
||||||
* specifically setting the context's level to ERROR
|
* specifically setting the context's level to ERROR
|
||||||
|
|
|
@ -2,12 +2,13 @@ module gogga.transform;
|
||||||
|
|
||||||
import dlog;
|
import dlog;
|
||||||
import gogga.context;
|
import gogga.context;
|
||||||
|
import std.conv : to;
|
||||||
|
|
||||||
// TODO: hehe easter egg TRADITIONAL, LIBERAL, UNHINGED
|
// TODO: hehe easter egg TRADITIONAL, LIBERAL, UNHINGED
|
||||||
public enum GoggaMode
|
public enum GoggaMode
|
||||||
{
|
{
|
||||||
SIMPLE,
|
|
||||||
TwoKTwenty3,
|
TwoKTwenty3,
|
||||||
|
SIMPLE,
|
||||||
RUSTACEAN
|
RUSTACEAN
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -39,12 +40,12 @@ public class GoggaTransform : MessageTransform
|
||||||
*/
|
*/
|
||||||
if(mode == GoggaMode.SIMPLE)
|
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>`
|
* TwoKTwenty3 is: `[<file>] (<module>:<lineNumber>) <message>`
|
||||||
*/
|
*/
|
||||||
else if(mode == Gogga.TwoKTwenty3)
|
else if(mode == GoggaMode.TwoKTwenty3)
|
||||||
{
|
{
|
||||||
/* Module information (and status debugColoring) */
|
/* Module information (and status debugColoring) */
|
||||||
string moduleInfo = cast(string)debugColor("["~context[1]~"]", level);
|
string moduleInfo = cast(string)debugColor("["~context[1]~"]", level);
|
||||||
|
@ -64,6 +65,11 @@ public class GoggaTransform : MessageTransform
|
||||||
|
|
||||||
return finalOutput;
|
return finalOutput;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void setMode(GoggaMode mode)
|
||||||
|
{
|
||||||
|
this.mode = mode;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private byte[] debugColor(string text, Level level)
|
private byte[] debugColor(string text, Level level)
|
||||||
|
@ -93,6 +99,9 @@ private byte[] debugColor(string text, Level level)
|
||||||
/* Switch back debugColor */
|
/* Switch back debugColor */
|
||||||
messageBytes ~= cast(byte[])[27, '[', '3', '9', 'm'];
|
messageBytes ~= cast(byte[])[27, '[', '3', '9', 'm'];
|
||||||
|
|
||||||
|
/* Reset coloring */
|
||||||
|
messageBytes ~= [27, '[', 'm'];
|
||||||
|
|
||||||
return messageBytes;
|
return messageBytes;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue