- Removed uneeded unittest with commented-out code
- Moved `GoggaTransform` outside of the `dlog.core` module

Transform

- Placed the `GoggaTransform` into the `dlog.transform` module

Context

- Placed `GoggaContext` into its own module named `gogga.context`
This commit is contained in:
Tristan B. Velloza Kildaire 2023-03-02 13:31:37 +02:00
parent a5cf167880
commit 7652938043
3 changed files with 87 additions and 94 deletions

8
source/gogga/context.d Normal file
View File

@ -0,0 +1,8 @@
module gogga.context;
import dlog;
public final class GoggaContext : Context
{
// TODO: Put more advanced stuff here
}

View File

@ -1,16 +1,11 @@
module gogga.core;
import std.conv : to;
import std.stdio : write, stdout;
// TODO: Remove (just for testing)
import std.stdio : writeln;
import dlog;
import dlog.utilities : flatten;
import std.array : join;
import gogga.transform;
import gogga.context;
unittest
{
@ -25,11 +20,6 @@ unittest
// TODO: Add debug stuff
}
public final class GoggaContext : Context
{
// TODO: Put more advanced stuff here
}
public class GoggaLogger : Logger
{
private GoggaTransform gTransform = new GoggaTransform();
@ -233,86 +223,4 @@ public class GoggaLogger : Logger
{
this.debugEnabled = false;
}
}
public class GoggaTransform : MessageTransform
{
private bool isSourceMode = false;
public override string transform(string text, Context ctx)
{
/* Get the GoggaContext */
GoggaContext gCtx = cast(GoggaContext)ctx;
/* Extract the line information */
CompilationInfo compInfo = gCtx.getLineInfo();
string[] context = compInfo.toArray();
/* Module information (and status debugColoring) */
string moduleInfo = cast(string)debugColor("["~context[1]~"]", gCtx.getLevel());
/* Function and line number info */
string funcInfo = cast(string)(colorSrc("("~context[4]~":"~context[2]~")"));
return moduleInfo~" "~funcInfo~" "~text~"\n";
}
}
private byte[] debugColor(string text, Level level)
{
/* The generated message */
byte[] messageBytes;
/* If INFO, set green */
if(level == Level.INFO)
{
messageBytes = cast(byte[])[27, '[','3','2','m'];
}
/* If WARNING, set warning */
else if(level == Level.WARN)
{
messageBytes = cast(byte[])[27, '[','3','5','m']; /* TODO: FInd yllow */
}
/* If ERROR, set error */
else if(level == Level.ERROR)
{
messageBytes = cast(byte[])[27, '[','3','1','m'];
}
/* Add the message */
messageBytes ~= cast(byte[])text;
/* Switch back debugColor */
messageBytes ~= cast(byte[])[27, '[', '3', '9', 'm'];
return messageBytes;
}
private byte[] colorSrc(string text)
{
/* The generated message */
byte[] messageBytes;
/* Reset coloring */
messageBytes ~= [27, '[', 'm'];
/* Color gray */
messageBytes ~= [27, '[', '3', '9', ';', '2', 'm'];
/* Append the message */
messageBytes ~= text;
/* Reset coloring */
messageBytes ~= [27, '[', 'm'];
return messageBytes;
}
unittest
{
// alias debugTypes = __traits(allMembers, DebugType);
// static foreach(debugType; debugTypes)
// {
// gprintln("Hello world", mixin("DebugType."~debugType));
// }
}

77
source/gogga/transform.d Normal file
View File

@ -0,0 +1,77 @@
module gogga.transform;
import dlog;
import gogga.context;
public class GoggaTransform : MessageTransform
{
private bool isSourceMode = false;
public override string transform(string text, Context ctx)
{
/* Get the GoggaContext */
GoggaContext gCtx = cast(GoggaContext)ctx;
/* Extract the line information */
CompilationInfo compInfo = gCtx.getLineInfo();
string[] context = compInfo.toArray();
/* Module information (and status debugColoring) */
string moduleInfo = cast(string)debugColor("["~context[1]~"]", gCtx.getLevel());
/* Function and line number info */
string funcInfo = cast(string)(colorSrc("("~context[4]~":"~context[2]~")"));
return moduleInfo~" "~funcInfo~" "~text~"\n";
}
}
private byte[] debugColor(string text, Level level)
{
/* The generated message */
byte[] messageBytes;
/* If INFO, set green */
if(level == Level.INFO)
{
messageBytes = cast(byte[])[27, '[','3','2','m'];
}
/* If WARNING, set warning */
else if(level == Level.WARN)
{
messageBytes = cast(byte[])[27, '[','3','5','m']; /* TODO: FInd yllow */
}
/* If ERROR, set error */
else if(level == Level.ERROR)
{
messageBytes = cast(byte[])[27, '[','3','1','m'];
}
/* Add the message */
messageBytes ~= cast(byte[])text;
/* Switch back debugColor */
messageBytes ~= cast(byte[])[27, '[', '3', '9', 'm'];
return messageBytes;
}
private byte[] colorSrc(string text)
{
/* The generated message */
byte[] messageBytes;
/* Reset coloring */
messageBytes ~= [27, '[', 'm'];
/* Color gray */
messageBytes ~= [27, '[', '3', '9', ';', '2', 'm'];
/* Append the message */
messageBytes ~= text;
/* Reset coloring */
messageBytes ~= [27, '[', 'm'];
return messageBytes;
}