mirror of
https://github.com/deavmi/gogga.git
synced 2025-02-16 09:56:49 +00:00
Core
- 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:
parent
a5cf167880
commit
7652938043
8
source/gogga/context.d
Normal file
8
source/gogga/context.d
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
module gogga.context;
|
||||||
|
|
||||||
|
import dlog;
|
||||||
|
|
||||||
|
public final class GoggaContext : Context
|
||||||
|
{
|
||||||
|
// TODO: Put more advanced stuff here
|
||||||
|
}
|
@ -1,16 +1,11 @@
|
|||||||
module gogga.core;
|
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;
|
||||||
import dlog.utilities : flatten;
|
import dlog.utilities : flatten;
|
||||||
import std.array : join;
|
import std.array : join;
|
||||||
|
|
||||||
|
import gogga.transform;
|
||||||
|
import gogga.context;
|
||||||
|
|
||||||
unittest
|
unittest
|
||||||
{
|
{
|
||||||
@ -25,11 +20,6 @@ unittest
|
|||||||
// TODO: Add debug stuff
|
// TODO: Add debug stuff
|
||||||
}
|
}
|
||||||
|
|
||||||
public final class GoggaContext : Context
|
|
||||||
{
|
|
||||||
// TODO: Put more advanced stuff here
|
|
||||||
}
|
|
||||||
|
|
||||||
public class GoggaLogger : Logger
|
public class GoggaLogger : Logger
|
||||||
{
|
{
|
||||||
private GoggaTransform gTransform = new GoggaTransform();
|
private GoggaTransform gTransform = new GoggaTransform();
|
||||||
@ -233,86 +223,4 @@ public class GoggaLogger : Logger
|
|||||||
{
|
{
|
||||||
this.debugEnabled = false;
|
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
77
source/gogga/transform.d
Normal 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;
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user