log specification of zero arg call was broken

some more
This commit is contained in:
Robert burner Schadek 2015-02-10 16:48:44 +01:00
parent a8150a9759
commit 2bca140b84

View file

@ -101,6 +101,7 @@ bool isLoggingEnabled()(LogLevel ll, LogLevel loggerLL,
return ll >= globalLL
&& ll >= loggerLL
&& ll != LogLevel.off
&& globalLL != LogLevel.off
&& loggerLL != LogLevel.off
&& condition;
@ -200,7 +201,7 @@ void log(int line = __LINE__, string file = __FILE__,
string funcName = __FUNCTION__, string prettyFuncName = __PRETTY_FUNCTION__,
string moduleName = __MODULE__, A...)(const LogLevel ll,
lazy bool condition, lazy A args) @safe
if (args.length > 1)
if (args.length != 1)
{
static if (isLoggingActive)
{
@ -265,8 +266,8 @@ void log(T, string moduleName = __MODULE__)(const LogLevel ll, lazy T arg,
{
if (ll >= moduleLogLevel!moduleName)
{
stdThreadLocalLog.log!T(ll, arg, line, file, funcName, prettyFuncName,
moduleName);
stdThreadLocalLog.log!T(ll, arg, line, file, funcName, prettyFuncName,
moduleName);
}
}
}
@ -289,7 +290,7 @@ log(true, "Hello World", 3.1415);
void log(int line = __LINE__, string file = __FILE__,
string funcName = __FUNCTION__, string prettyFuncName = __PRETTY_FUNCTION__,
string moduleName = __MODULE__, A...)(lazy bool condition, lazy A args)
if (args.length > 1)
if (args.length != 1)
{
static if (isLoggingActive)
{
@ -326,13 +327,14 @@ log("Hello World", 3.1415);
void log(int line = __LINE__, string file = __FILE__,
string funcName = __FUNCTION__, string prettyFuncName = __PRETTY_FUNCTION__,
string moduleName = __MODULE__, A...)(lazy A args)
if (args.length > 1 && !is(Unqual!(A[0]) : bool)
&& !is(Unqual!(A[0]) == LogLevel))
if ((args.length > 1 && !is(Unqual!(A[0]) : bool)
&& !is(Unqual!(A[0]) == LogLevel))
|| args.length == 0)
{
static if (isLoggingActive)
{
stdThreadLocalLog.log!(line, file, funcName,
prettyFuncName, moduleName)(stdThreadLocalLog.logLevel, args);
prettyFuncName, moduleName)(stdThreadLocalLog.logLevel, args);
}
}
@ -482,7 +484,7 @@ template defaultLogFunction(LogLevel ll)
static if (isLoggingActiveAt!ll && ll >= moduleLogLevel!moduleName)
{
stdThreadLocalLog.memLogFunctions!(ll).logImpl!(line, file, funcName,
prettyFuncName, moduleName)(args);
prettyFuncName, moduleName)(args);
}
}
@ -495,7 +497,7 @@ template defaultLogFunction(LogLevel ll)
static if (isLoggingActiveAt!ll && ll >= moduleLogLevel!moduleName)
{
stdThreadLocalLog.memLogFunctions!(ll).logImpl!(line, file, funcName,
prettyFuncName, moduleName)(condition, args);
prettyFuncName, moduleName)(condition, args);
}
}
}
@ -572,7 +574,7 @@ template defaultLogFunctionf(LogLevel ll)
static if (isLoggingActiveAt!ll && ll >= moduleLogLevel!moduleName)
{
stdThreadLocalLog.memLogFunctions!(ll).logImplf!(line, file, funcName,
prettyFuncName, moduleName)(msg, args);
prettyFuncName, moduleName)(msg, args);
}
}
@ -585,7 +587,7 @@ template defaultLogFunctionf(LogLevel ll)
static if (isLoggingActiveAt!ll && ll >= moduleLogLevel!moduleName)
{
stdThreadLocalLog.memLogFunctions!(ll).logImplf!(line, file, funcName,
prettyFuncName, moduleName)(condition, msg, args);
prettyFuncName, moduleName)(condition, msg, args);
}
}
}
@ -1176,7 +1178,7 @@ abstract class Logger
string prettyFuncName = __PRETTY_FUNCTION__,
string moduleName = __MODULE__, A...)(const LogLevel ll,
lazy bool condition, lazy A args) @safe
if (args.length > 1)
if (args.length != 1)
{
static if (isLoggingActive) synchronized (mutex)
{
@ -1246,7 +1248,7 @@ abstract class Logger
string prettyFuncName = __PRETTY_FUNCTION__,
string moduleName = __MODULE__, A...)(const LogLevel ll, lazy A args)
@safe
if (args.length > 1 && !is(Unqual!(A[0]) : bool))
if ((args.length > 1 && !is(Unqual!(A[0]) : bool)) || args.length == 0)
{
static if (isLoggingActive) synchronized (mutex)
{
@ -1316,7 +1318,7 @@ abstract class Logger
string prettyFuncName = __PRETTY_FUNCTION__,
string moduleName = __MODULE__, A...)(lazy bool condition, lazy A args)
@safe
if (args.length > 1)
if (args.length != 1)
{
static if (isLoggingActive) synchronized (mutex)
{
@ -1386,9 +1388,10 @@ abstract class Logger
string prettyFuncName = __PRETTY_FUNCTION__,
string moduleName = __MODULE__, A...)(lazy A args)
@safe
if (args.length > 1
if ((args.length > 1
&& !is(Unqual!(A[0]) : bool)
&& !is(Unqual!(A[0]) == LogLevel))
|| args.length == 0)
{
static if (isLoggingActive) synchronized (mutex)
{
@ -1883,6 +1886,44 @@ version (unittest)
assert(tl1.msg == "I'm here", tl1.msg);
}
@safe unittest
{
auto tl1 = new TestLogger(LogLevel.all);
tl1.log();
assert(tl1.line == __LINE__ - 1);
tl1.log(true);
assert(tl1.line == __LINE__ - 1);
tl1.log(false);
assert(tl1.line == __LINE__ - 3);
tl1.log(LogLevel.info);
assert(tl1.line == __LINE__ - 1);
tl1.log(LogLevel.off);
assert(tl1.line == __LINE__ - 3);
tl1.log(LogLevel.info, true);
assert(tl1.line == __LINE__ - 1);
tl1.log(LogLevel.info, false);
assert(tl1.line == __LINE__ - 3);
auto oldunspecificLogger = sharedLog;
scope(exit) {
sharedLog = oldunspecificLogger;
}
sharedLog = tl1;
log();
assert(tl1.line == __LINE__ - 1);
log(LogLevel.info);
assert(tl1.line == __LINE__ - 1);
log(true);
assert(tl1.line == __LINE__ - 1);
log(LogLevel.warning, true);
assert(tl1.line == __LINE__ - 1);
}
@safe unittest
{
import std.experimental.logger.multilogger : MultiLogger;
@ -1932,7 +1973,7 @@ version (unittest)
l.log(true, msg);
lineNumber = __LINE__ - 1;
assert(l.msg == msg);
assert(l.msg == msg, l.msg);
assert(l.line == lineNumber);
assert(l.logLevel == LogLevel.all);
@ -2328,14 +2369,15 @@ unittest
string valueStr = to!string(value);
++value;
bool ll2Off = (ll2 != LogLevel.off);
bool gllOff = (gll != LogLevel.off);
bool llOff = (ll != LogLevel.off);
bool condFalse = (cond ? condValue : true);
bool ll2VSgll = (ll2 >= gll);
bool ll2VSll = (ll2 >= ll);
bool shouldLog = gllOff && llOff && condFalse
&& ll2VSgll && ll2VSll;
bool shouldLog = ll2Off && gllOff && llOff
&& condFalse && ll2VSgll && ll2VSll;
/*
writefln(
@ -2350,11 +2392,11 @@ unittest
{
assert(mem.msg.indexOf(valueStr) != -1,
format(
"lineCall(%d) gll(%u) ll(%u) ll2(%u) " ~
"lineCall(%d) ll2Off(%u) gll(%u) ll(%u) ll2(%u) " ~
"cond(%b) condValue(%b)" ~
" memOrG(%b) shouldLog(%b) %s == %s" ~
" %b %b %b %b %b",
lineCall, gll, ll, ll2, cond,
lineCall, ll2Off, gll, ll, ll2, cond,
condValue, memOrG, shouldLog, mem.msg,
valueStr, gllOff, llOff, condFalse,
ll2VSgll, ll2VSll
@ -2364,11 +2406,14 @@ unittest
{
assert(mem.msg.indexOf(valueStr),
format(
"lineCall(%d) gll(%u) ll(%u) ll2(%u) " ~
" cond(%b)condValue(%b) memOrG(%b) " ~
"shouldLog(%b) %s != %s", gll,
lineCall, ll, ll2, cond, condValue,
memOrG, shouldLog, mem.msg, valueStr
"lineCall(%d) ll2Off(%u) gll(%u) ll(%u) ll2(%u) " ~
"cond(%b) condValue(%b)" ~
" memOrG(%b) shouldLog(%b) %s == %s" ~
" %b %b %b %b %b",
lineCall, ll2Off, gll, ll, ll2, cond,
condValue, memOrG, shouldLog, mem.msg,
valueStr, gllOff, llOff, condFalse,
ll2VSgll, ll2VSll
));
}
}