mirror of https://github.com/deavmi/gogga.git
Compare commits
4 Commits
Author | SHA1 | Date |
---|---|---|
Tristan B. Velloza Kildaire | 7e14ec68a8 | |
Tristan B. Velloza Kildaire | 974e8cf019 | |
Tristan B. Velloza Kildaire | 05c74b1aa4 | |
Tristan B. Velloza Kildaire | fd678eb9fd |
|
@ -31,9 +31,9 @@ This should output something like the following:
|
||||||
|
|
||||||
![](example.png)
|
![](example.png)
|
||||||
|
|
||||||
Various [styles](https://gogga.dpldocs.info/v2.2.1/gogga.transform.GoggaMode.html) are supported which can be set using `mode(GoggaMode)`.
|
Various [styles](https://gogga.dpldocs.info/v3.0.1/gogga.core.GoggaMode.html) are supported which can be set using `mode(GoggaMode)`.
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
Or you can also [View the full API](https://gogga.dpldocs.info/v2.2.1/index.html).
|
Or you can also [View the full API](https://gogga.dpldocs.info/v3.0.1/gogga.html).
|
||||||
|
|
||||||
|
|
2
dub.json
2
dub.json
|
@ -7,7 +7,7 @@
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"dlog": ">=1.0.0"
|
"dlog": ">=1.0.0"
|
||||||
},
|
},
|
||||||
"description": "Simple VT100 colourised pretty-printing logger",
|
"description": "Plug-and-play colorful VT100 logging for your terminal",
|
||||||
"license": "LGPL 3.0",
|
"license": "LGPL 3.0",
|
||||||
"name": "gogga",
|
"name": "gogga",
|
||||||
"targetType": "library"
|
"targetType": "library"
|
||||||
|
|
|
@ -40,7 +40,7 @@ public enum GoggaMode
|
||||||
/**
|
/**
|
||||||
* Information obtained during compilation time (if any)
|
* Information obtained during compilation time (if any)
|
||||||
*/
|
*/
|
||||||
private struct GoggaCompInfo
|
public struct GoggaCompInfo
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* compile time usage file
|
* compile time usage file
|
||||||
|
@ -292,7 +292,7 @@ public final class GoggaLogger : BasicLogger
|
||||||
* info = the context
|
* info = the context
|
||||||
* level = the log level to use
|
* level = the log level to use
|
||||||
*/
|
*/
|
||||||
private void doLog(TextType...)(TextType segments, GoggaCompInfo info, Level level)
|
public void doLog(TextType...)(TextType segments, GoggaCompInfo info, Level level)
|
||||||
{
|
{
|
||||||
/* Create a new GoggaMessage */
|
/* Create a new GoggaMessage */
|
||||||
GoggaMessage message = new GoggaMessage();
|
GoggaMessage message = new GoggaMessage();
|
||||||
|
|
|
@ -0,0 +1,91 @@
|
||||||
|
/**
|
||||||
|
* Extra helper utilities
|
||||||
|
*
|
||||||
|
* Authors: Tristan Brice Velloza Kildaire (deavmi)
|
||||||
|
*/
|
||||||
|
module gogga.extras;
|
||||||
|
|
||||||
|
import gogga.core : GoggaLogger;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Mixes in a set of easy helper methods
|
||||||
|
* for each log-level in `Level`, with
|
||||||
|
* matching nams
|
||||||
|
*
|
||||||
|
* Params:
|
||||||
|
* gLogger = the `GoggaLogger` identifier
|
||||||
|
*/
|
||||||
|
public mixin template LoggingFuncs(alias gLogger)
|
||||||
|
if(__traits(isSame, typeof(gLogger), GoggaLogger))
|
||||||
|
{
|
||||||
|
import std.meta : AliasSeq, aliasSeqOf;
|
||||||
|
import std.traits : ParameterDefaults;
|
||||||
|
import std.traits : EnumMembers;
|
||||||
|
import dlog.basic : Level;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Generatesd a function named after
|
||||||
|
* the given log level and using
|
||||||
|
* the log level provided with
|
||||||
|
* the correct default (call-site
|
||||||
|
* based) arguments containing
|
||||||
|
* line information
|
||||||
|
*
|
||||||
|
* Params:
|
||||||
|
* gLogger = the logger identifier
|
||||||
|
* level = the log level
|
||||||
|
*/
|
||||||
|
private mixin template MakeFuncFor(alias GoggaLogger gLogger, Level level)
|
||||||
|
{
|
||||||
|
import std.conv : to;
|
||||||
|
import gogga.core : GoggaCompInfo;
|
||||||
|
mixin(`
|
||||||
|
public void `~to!(string)(level)~`(Text...)
|
||||||
|
(
|
||||||
|
Text segments,
|
||||||
|
string c1 = __FILE_FULL_PATH__,
|
||||||
|
string c2 = __FILE__,
|
||||||
|
ulong c3 = __LINE__,
|
||||||
|
string c4 = __MODULE__,
|
||||||
|
string c5 = __FUNCTION__,
|
||||||
|
string c6 = __PRETTY_FUNCTION__
|
||||||
|
)
|
||||||
|
{
|
||||||
|
gLogger.doLog(segments, GoggaCompInfo(c1, c2, c3, c4, c5, c6), Level.`~to!(string)(level)~`);
|
||||||
|
}
|
||||||
|
`);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Generate methods per each log level
|
||||||
|
static foreach(level; EnumMembers!(Level))
|
||||||
|
{
|
||||||
|
mixin MakeFuncFor!(gLogger, level);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
version(unittest)
|
||||||
|
{
|
||||||
|
import gogga.extras;
|
||||||
|
import std.stdio : writeln, stdout;
|
||||||
|
import dlog.basic : Level, FileHandler;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Tests using the mixin for method
|
||||||
|
* names
|
||||||
|
*/
|
||||||
|
unittest
|
||||||
|
{
|
||||||
|
GoggaLogger gLogger = new GoggaLogger();
|
||||||
|
gLogger.addHandler(new FileHandler(stdout));
|
||||||
|
gLogger.setLevel(Level.DEBUG);
|
||||||
|
|
||||||
|
mixin LoggingFuncs!(gLogger);
|
||||||
|
|
||||||
|
DEBUG("This is debug", 2.3, true, [2,2]);
|
||||||
|
ERROR("This is error", 2.3, true, [2,2]);
|
||||||
|
INFO("This is info", 2.3, true, [2,2]);
|
||||||
|
WARN("This is warn", 2.3, true, [2,2]);
|
||||||
|
|
||||||
|
writeln();
|
||||||
|
}
|
|
@ -0,0 +1,30 @@
|
||||||
|
/**
|
||||||
|
* Out-of-module tests
|
||||||
|
*
|
||||||
|
* Authors: Tristan Brice Velloza Kildaire (deavmi)
|
||||||
|
*/
|
||||||
|
module gogga.test;
|
||||||
|
|
||||||
|
version(unittest)
|
||||||
|
{
|
||||||
|
import gogga;
|
||||||
|
import gogga.extras;
|
||||||
|
import std.stdio : writeln, stdout;
|
||||||
|
import dlog.basic : Level, FileHandler;
|
||||||
|
}
|
||||||
|
|
||||||
|
private unittest
|
||||||
|
{
|
||||||
|
GoggaLogger gLogger = new GoggaLogger();
|
||||||
|
gLogger.addHandler(new FileHandler(stdout));
|
||||||
|
gLogger.setLevel(Level.DEBUG);
|
||||||
|
|
||||||
|
mixin LoggingFuncs!(gLogger);
|
||||||
|
|
||||||
|
DEBUG("This is debug", 2.3, true, [2,2]);
|
||||||
|
ERROR("This is error", 2.3, true, [2,2]);
|
||||||
|
INFO("This is info", 2.3, true, [2,2]);
|
||||||
|
WARN("This is warn", 2.3, true, [2,2]);
|
||||||
|
|
||||||
|
writeln();
|
||||||
|
}
|
Loading…
Reference in New Issue