mirror of https://github.com/deavmi/dlog.git
Core
- Bug fix for the usage of `contextExtras` (which was not working prior) Unit tests - Added a new unit test to fix the `contextExtras` feature of `log(...)`
This commit is contained in:
parent
b2b5d46d8e
commit
bf2e54904b
|
@ -100,8 +100,19 @@ public class Logger
|
|||
public final void log(TextType...)(TextType message, string c1 = __FILE_FULL_PATH__,
|
||||
string c2 = __FILE__, ulong c3 = __LINE__,
|
||||
string c4 = __MODULE__, string c5 = __FUNCTION__,
|
||||
string c6 = __PRETTY_FUNCTION__, string[] contextExtras = null)
|
||||
string c6 = __PRETTY_FUNCTION__)
|
||||
{
|
||||
/* Default context extras ios nothing */
|
||||
string[] contextExtras = null;
|
||||
version(unittest)
|
||||
{
|
||||
static if(__traits(isSame, typeof(message[$-1]), mixin(`string[]`)))
|
||||
{
|
||||
contextExtras = message[$-1];
|
||||
pragma(msg, "meta: log: Found a custom string[] context array");
|
||||
}
|
||||
}
|
||||
|
||||
/* Construct context array */
|
||||
string[] context = [c1, c2, to!(string)(c3), c4, c5, c6]~contextExtras;
|
||||
|
||||
|
@ -166,6 +177,34 @@ unittest
|
|||
writeln();
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests the DefaultLogger but custom `log()` context
|
||||
*/
|
||||
unittest
|
||||
{
|
||||
writeln();
|
||||
writeln();
|
||||
|
||||
Logger logger = new DefaultLogger();
|
||||
|
||||
alias testParameters = AliasSeq!("This is a log message", 1.1, true, [1,2,3], 'f', logger);
|
||||
|
||||
|
||||
// Test various types one-by-one
|
||||
static foreach(testParameter; testParameters)
|
||||
{
|
||||
logger.log(testParameter, ["cool context"]);
|
||||
}
|
||||
|
||||
// Test various parameters (of various types) all at once
|
||||
logger.log(testParameters, ["cool context"]);
|
||||
|
||||
// Same as above but with a custom joiner set
|
||||
logger = new DefaultLogger("(-)");
|
||||
logger.log(testParameters, ["cool context"]);
|
||||
|
||||
writeln();
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests the `log2()` method using the DefaultLogger
|
||||
|
|
Loading…
Reference in New Issue