Skip to content

Commit

Permalink
log specification of zero arg call was broken
Browse files Browse the repository at this point in the history
some more
  • Loading branch information
burner committed Feb 10, 2015
1 parent a8150a9 commit 2bca140
Showing 1 changed file with 70 additions and 25 deletions.
95 changes: 70 additions & 25 deletions std/experimental/logger/core.d
Expand Up @@ -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;
Expand Down Expand Up @@ -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)
{
Expand Down Expand Up @@ -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);
}
}
}
Expand All @@ -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)
{
Expand Down Expand Up @@ -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);
}
}

Expand Down Expand Up @@ -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);
}
}

Expand All @@ -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);
}
}
}
Expand Down Expand Up @@ -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);
}
}

Expand All @@ -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);
}
}
}
Expand Down Expand Up @@ -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)
{
Expand Down Expand Up @@ -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)
{
Expand Down Expand Up @@ -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)
{
Expand Down Expand Up @@ -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)
{
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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);

Expand Down Expand Up @@ -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(
Expand All @@ -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
Expand All @@ -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
));
}
}
Expand Down

0 comments on commit 2bca140

Please sign in to comment.