mirror of https://github.com/deavmi/dlog.git
Repository
- Updated .gitignore Clean up - General clean up
This commit is contained in:
parent
c410dd3bc0
commit
6008c8f333
|
@ -1,3 +1,4 @@
|
|||
.dub/
|
||||
*test-library*
|
||||
*.lst
|
||||
libdlog.a
|
||||
|
|
|
@ -7,48 +7,9 @@ module dlog.core;
|
|||
|
||||
import std.conv : to;
|
||||
import std.range : join;
|
||||
import dlog.transform : MessageTransform;
|
||||
import dlog.defaults;
|
||||
|
||||
/**
|
||||
* DefaultTransform
|
||||
*
|
||||
* Provides a transformation of the kind
|
||||
*
|
||||
* [date+time] (srcFile:lineNumber): message `\n`
|
||||
*/
|
||||
public final class DefaultTransform : MessageTransform
|
||||
{
|
||||
/**
|
||||
* Performs the default transformation
|
||||
*
|
||||
* Params:
|
||||
* text = text input to transform
|
||||
* context = the context (if any)
|
||||
* Returns: the transformed text
|
||||
*/
|
||||
public override string transform(string text, string[] context)
|
||||
{
|
||||
string message;
|
||||
|
||||
/* Date and time */
|
||||
import std.datetime.systime : Clock, SysTime;
|
||||
SysTime currTime = Clock.currTime();
|
||||
import std.conv : to;
|
||||
string timestamp = to!(string)(currTime);
|
||||
message = "["~timestamp~"]";
|
||||
|
||||
/* Module information */
|
||||
message = message ~ "\t(";
|
||||
message = message ~ context[1]~":"~context[2];
|
||||
message = message ~ "): "~text;
|
||||
|
||||
/* Add trailing newline */
|
||||
message = message ~ '\n';
|
||||
|
||||
return message;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Logger
|
||||
*
|
||||
|
@ -117,51 +78,7 @@ public class Logger
|
|||
protected abstract void logImpl(string message);
|
||||
}
|
||||
|
||||
/**
|
||||
* MessageTransform
|
||||
*
|
||||
* A message transform takes in text, applies
|
||||
* a transformation to it and outputs said text
|
||||
*
|
||||
* Transforms may be chained
|
||||
*/
|
||||
public abstract class MessageTransform
|
||||
{
|
||||
/* Next transformation (if any) */
|
||||
private MessageTransform chainedTransform;
|
||||
|
||||
/**
|
||||
* The actual textual transformation.
|
||||
*
|
||||
* This is to be implemented by sub-classes
|
||||
*/
|
||||
public abstract string transform(string text, string[] context);
|
||||
|
||||
/**
|
||||
* Chain a transform
|
||||
*/
|
||||
public final void chain(MessageTransform transform)
|
||||
{
|
||||
chainedTransform = transform;
|
||||
}
|
||||
|
||||
/**
|
||||
* Perform the transformation
|
||||
*/
|
||||
public final string execute(string text, string[] context)
|
||||
{
|
||||
/* Perform the transformation */
|
||||
string transformedText = transform(text, context);
|
||||
|
||||
/* If there is a chained transformation */
|
||||
if(chainedTransform)
|
||||
{
|
||||
transformedText = chainedTransform.execute(transformedText, context);
|
||||
}
|
||||
|
||||
return transformedText;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests the DefaultLogger
|
||||
|
|
|
@ -4,6 +4,7 @@
|
|||
module dlog.defaults;
|
||||
|
||||
import dlog.core : Logger;
|
||||
import dlog.transform : MessageTransform;
|
||||
|
||||
/**
|
||||
* DefaultLogger
|
||||
|
@ -24,3 +25,43 @@ public final class DefaultLogger : Logger
|
|||
write(message);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* DefaultTransform
|
||||
*
|
||||
* Provides a transformation of the kind
|
||||
*
|
||||
* [date+time] (srcFile:lineNumber): message `\n`
|
||||
*/
|
||||
public final class DefaultTransform : MessageTransform
|
||||
{
|
||||
/**
|
||||
* Performs the default transformation
|
||||
*
|
||||
* Params:
|
||||
* text = text input to transform
|
||||
* context = the context (if any)
|
||||
* Returns: the transformed text
|
||||
*/
|
||||
public override string transform(string text, string[] context)
|
||||
{
|
||||
string message;
|
||||
|
||||
/* Date and time */
|
||||
import std.datetime.systime : Clock, SysTime;
|
||||
SysTime currTime = Clock.currTime();
|
||||
import std.conv : to;
|
||||
string timestamp = to!(string)(currTime);
|
||||
message = "["~timestamp~"]";
|
||||
|
||||
/* Module information */
|
||||
message = message ~ "\t(";
|
||||
message = message ~ context[1]~":"~context[2];
|
||||
message = message ~ "): "~text;
|
||||
|
||||
/* Add trailing newline */
|
||||
message = message ~ '\n';
|
||||
|
||||
return message;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,47 @@
|
|||
module dlog.transform;
|
||||
|
||||
/**
|
||||
* MessageTransform
|
||||
*
|
||||
* A message transform takes in text, applies
|
||||
* a transformation to it and outputs said text
|
||||
*
|
||||
* Transforms may be chained
|
||||
*/
|
||||
public abstract class MessageTransform
|
||||
{
|
||||
/* Next transformation (if any) */
|
||||
private MessageTransform chainedTransform;
|
||||
|
||||
/**
|
||||
* The actual textual transformation.
|
||||
*
|
||||
* This is to be implemented by sub-classes
|
||||
*/
|
||||
public abstract string transform(string text, string[] context);
|
||||
|
||||
/**
|
||||
* Chain a transform
|
||||
*/
|
||||
public final void chain(MessageTransform transform)
|
||||
{
|
||||
chainedTransform = transform;
|
||||
}
|
||||
|
||||
/**
|
||||
* Perform the transformation
|
||||
*/
|
||||
public final string execute(string text, string[] context)
|
||||
{
|
||||
/* Perform the transformation */
|
||||
string transformedText = transform(text, context);
|
||||
|
||||
/* If there is a chained transformation */
|
||||
if(chainedTransform)
|
||||
{
|
||||
transformedText = chainedTransform.execute(transformedText, context);
|
||||
}
|
||||
|
||||
return transformedText;
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue