mirror of
https://github.com/dlang/phobos.git
synced 2025-04-29 14:40:30 +03:00
log specification of zero arg call was broken
some more
This commit is contained in:
parent
a8150a9759
commit
2bca140b84
1 changed files with 70 additions and 25 deletions
|
@ -101,6 +101,7 @@ bool isLoggingEnabled()(LogLevel ll, LogLevel loggerLL,
|
||||||
|
|
||||||
return ll >= globalLL
|
return ll >= globalLL
|
||||||
&& ll >= loggerLL
|
&& ll >= loggerLL
|
||||||
|
&& ll != LogLevel.off
|
||||||
&& globalLL != LogLevel.off
|
&& globalLL != LogLevel.off
|
||||||
&& loggerLL != LogLevel.off
|
&& loggerLL != LogLevel.off
|
||||||
&& condition;
|
&& condition;
|
||||||
|
@ -200,7 +201,7 @@ void log(int line = __LINE__, string file = __FILE__,
|
||||||
string funcName = __FUNCTION__, string prettyFuncName = __PRETTY_FUNCTION__,
|
string funcName = __FUNCTION__, string prettyFuncName = __PRETTY_FUNCTION__,
|
||||||
string moduleName = __MODULE__, A...)(const LogLevel ll,
|
string moduleName = __MODULE__, A...)(const LogLevel ll,
|
||||||
lazy bool condition, lazy A args) @safe
|
lazy bool condition, lazy A args) @safe
|
||||||
if (args.length > 1)
|
if (args.length != 1)
|
||||||
{
|
{
|
||||||
static if (isLoggingActive)
|
static if (isLoggingActive)
|
||||||
{
|
{
|
||||||
|
@ -265,8 +266,8 @@ void log(T, string moduleName = __MODULE__)(const LogLevel ll, lazy T arg,
|
||||||
{
|
{
|
||||||
if (ll >= moduleLogLevel!moduleName)
|
if (ll >= moduleLogLevel!moduleName)
|
||||||
{
|
{
|
||||||
stdThreadLocalLog.log!T(ll, arg, line, file, funcName, prettyFuncName,
|
stdThreadLocalLog.log!T(ll, arg, line, file, funcName, prettyFuncName,
|
||||||
moduleName);
|
moduleName);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -289,7 +290,7 @@ log(true, "Hello World", 3.1415);
|
||||||
void log(int line = __LINE__, string file = __FILE__,
|
void log(int line = __LINE__, string file = __FILE__,
|
||||||
string funcName = __FUNCTION__, string prettyFuncName = __PRETTY_FUNCTION__,
|
string funcName = __FUNCTION__, string prettyFuncName = __PRETTY_FUNCTION__,
|
||||||
string moduleName = __MODULE__, A...)(lazy bool condition, lazy A args)
|
string moduleName = __MODULE__, A...)(lazy bool condition, lazy A args)
|
||||||
if (args.length > 1)
|
if (args.length != 1)
|
||||||
{
|
{
|
||||||
static if (isLoggingActive)
|
static if (isLoggingActive)
|
||||||
{
|
{
|
||||||
|
@ -326,13 +327,14 @@ log("Hello World", 3.1415);
|
||||||
void log(int line = __LINE__, string file = __FILE__,
|
void log(int line = __LINE__, string file = __FILE__,
|
||||||
string funcName = __FUNCTION__, string prettyFuncName = __PRETTY_FUNCTION__,
|
string funcName = __FUNCTION__, string prettyFuncName = __PRETTY_FUNCTION__,
|
||||||
string moduleName = __MODULE__, A...)(lazy A args)
|
string moduleName = __MODULE__, A...)(lazy A args)
|
||||||
if (args.length > 1 && !is(Unqual!(A[0]) : bool)
|
if ((args.length > 1 && !is(Unqual!(A[0]) : bool)
|
||||||
&& !is(Unqual!(A[0]) == LogLevel))
|
&& !is(Unqual!(A[0]) == LogLevel))
|
||||||
|
|| args.length == 0)
|
||||||
{
|
{
|
||||||
static if (isLoggingActive)
|
static if (isLoggingActive)
|
||||||
{
|
{
|
||||||
stdThreadLocalLog.log!(line, file, funcName,
|
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)
|
static if (isLoggingActiveAt!ll && ll >= moduleLogLevel!moduleName)
|
||||||
{
|
{
|
||||||
stdThreadLocalLog.memLogFunctions!(ll).logImpl!(line, file, funcName,
|
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)
|
static if (isLoggingActiveAt!ll && ll >= moduleLogLevel!moduleName)
|
||||||
{
|
{
|
||||||
stdThreadLocalLog.memLogFunctions!(ll).logImpl!(line, file, funcName,
|
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)
|
static if (isLoggingActiveAt!ll && ll >= moduleLogLevel!moduleName)
|
||||||
{
|
{
|
||||||
stdThreadLocalLog.memLogFunctions!(ll).logImplf!(line, file, funcName,
|
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)
|
static if (isLoggingActiveAt!ll && ll >= moduleLogLevel!moduleName)
|
||||||
{
|
{
|
||||||
stdThreadLocalLog.memLogFunctions!(ll).logImplf!(line, file, funcName,
|
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 prettyFuncName = __PRETTY_FUNCTION__,
|
||||||
string moduleName = __MODULE__, A...)(const LogLevel ll,
|
string moduleName = __MODULE__, A...)(const LogLevel ll,
|
||||||
lazy bool condition, lazy A args) @safe
|
lazy bool condition, lazy A args) @safe
|
||||||
if (args.length > 1)
|
if (args.length != 1)
|
||||||
{
|
{
|
||||||
static if (isLoggingActive) synchronized (mutex)
|
static if (isLoggingActive) synchronized (mutex)
|
||||||
{
|
{
|
||||||
|
@ -1246,7 +1248,7 @@ abstract class Logger
|
||||||
string prettyFuncName = __PRETTY_FUNCTION__,
|
string prettyFuncName = __PRETTY_FUNCTION__,
|
||||||
string moduleName = __MODULE__, A...)(const LogLevel ll, lazy A args)
|
string moduleName = __MODULE__, A...)(const LogLevel ll, lazy A args)
|
||||||
@safe
|
@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)
|
static if (isLoggingActive) synchronized (mutex)
|
||||||
{
|
{
|
||||||
|
@ -1316,7 +1318,7 @@ abstract class Logger
|
||||||
string prettyFuncName = __PRETTY_FUNCTION__,
|
string prettyFuncName = __PRETTY_FUNCTION__,
|
||||||
string moduleName = __MODULE__, A...)(lazy bool condition, lazy A args)
|
string moduleName = __MODULE__, A...)(lazy bool condition, lazy A args)
|
||||||
@safe
|
@safe
|
||||||
if (args.length > 1)
|
if (args.length != 1)
|
||||||
{
|
{
|
||||||
static if (isLoggingActive) synchronized (mutex)
|
static if (isLoggingActive) synchronized (mutex)
|
||||||
{
|
{
|
||||||
|
@ -1386,9 +1388,10 @@ abstract class Logger
|
||||||
string prettyFuncName = __PRETTY_FUNCTION__,
|
string prettyFuncName = __PRETTY_FUNCTION__,
|
||||||
string moduleName = __MODULE__, A...)(lazy A args)
|
string moduleName = __MODULE__, A...)(lazy A args)
|
||||||
@safe
|
@safe
|
||||||
if (args.length > 1
|
if ((args.length > 1
|
||||||
&& !is(Unqual!(A[0]) : bool)
|
&& !is(Unqual!(A[0]) : bool)
|
||||||
&& !is(Unqual!(A[0]) == LogLevel))
|
&& !is(Unqual!(A[0]) == LogLevel))
|
||||||
|
|| args.length == 0)
|
||||||
{
|
{
|
||||||
static if (isLoggingActive) synchronized (mutex)
|
static if (isLoggingActive) synchronized (mutex)
|
||||||
{
|
{
|
||||||
|
@ -1883,6 +1886,44 @@ version (unittest)
|
||||||
assert(tl1.msg == "I'm here", tl1.msg);
|
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
|
@safe unittest
|
||||||
{
|
{
|
||||||
import std.experimental.logger.multilogger : MultiLogger;
|
import std.experimental.logger.multilogger : MultiLogger;
|
||||||
|
@ -1932,7 +1973,7 @@ version (unittest)
|
||||||
|
|
||||||
l.log(true, msg);
|
l.log(true, msg);
|
||||||
lineNumber = __LINE__ - 1;
|
lineNumber = __LINE__ - 1;
|
||||||
assert(l.msg == msg);
|
assert(l.msg == msg, l.msg);
|
||||||
assert(l.line == lineNumber);
|
assert(l.line == lineNumber);
|
||||||
assert(l.logLevel == LogLevel.all);
|
assert(l.logLevel == LogLevel.all);
|
||||||
|
|
||||||
|
@ -2328,14 +2369,15 @@ unittest
|
||||||
string valueStr = to!string(value);
|
string valueStr = to!string(value);
|
||||||
++value;
|
++value;
|
||||||
|
|
||||||
|
bool ll2Off = (ll2 != LogLevel.off);
|
||||||
bool gllOff = (gll != LogLevel.off);
|
bool gllOff = (gll != LogLevel.off);
|
||||||
bool llOff = (ll != LogLevel.off);
|
bool llOff = (ll != LogLevel.off);
|
||||||
bool condFalse = (cond ? condValue : true);
|
bool condFalse = (cond ? condValue : true);
|
||||||
bool ll2VSgll = (ll2 >= gll);
|
bool ll2VSgll = (ll2 >= gll);
|
||||||
bool ll2VSll = (ll2 >= ll);
|
bool ll2VSll = (ll2 >= ll);
|
||||||
|
|
||||||
bool shouldLog = gllOff && llOff && condFalse
|
bool shouldLog = ll2Off && gllOff && llOff
|
||||||
&& ll2VSgll && ll2VSll;
|
&& condFalse && ll2VSgll && ll2VSll;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
writefln(
|
writefln(
|
||||||
|
@ -2350,11 +2392,11 @@ unittest
|
||||||
{
|
{
|
||||||
assert(mem.msg.indexOf(valueStr) != -1,
|
assert(mem.msg.indexOf(valueStr) != -1,
|
||||||
format(
|
format(
|
||||||
"lineCall(%d) gll(%u) ll(%u) ll2(%u) " ~
|
"lineCall(%d) ll2Off(%u) gll(%u) ll(%u) ll2(%u) " ~
|
||||||
"cond(%b) condValue(%b)" ~
|
"cond(%b) condValue(%b)" ~
|
||||||
" memOrG(%b) shouldLog(%b) %s == %s" ~
|
" memOrG(%b) shouldLog(%b) %s == %s" ~
|
||||||
" %b %b %b %b %b",
|
" %b %b %b %b %b",
|
||||||
lineCall, gll, ll, ll2, cond,
|
lineCall, ll2Off, gll, ll, ll2, cond,
|
||||||
condValue, memOrG, shouldLog, mem.msg,
|
condValue, memOrG, shouldLog, mem.msg,
|
||||||
valueStr, gllOff, llOff, condFalse,
|
valueStr, gllOff, llOff, condFalse,
|
||||||
ll2VSgll, ll2VSll
|
ll2VSgll, ll2VSll
|
||||||
|
@ -2364,11 +2406,14 @@ unittest
|
||||||
{
|
{
|
||||||
assert(mem.msg.indexOf(valueStr),
|
assert(mem.msg.indexOf(valueStr),
|
||||||
format(
|
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) " ~
|
"cond(%b) condValue(%b)" ~
|
||||||
"shouldLog(%b) %s != %s", gll,
|
" memOrG(%b) shouldLog(%b) %s == %s" ~
|
||||||
lineCall, ll, ll2, cond, condValue,
|
" %b %b %b %b %b",
|
||||||
memOrG, shouldLog, mem.msg, valueStr
|
lineCall, ll2Off, gll, ll, ll2, cond,
|
||||||
|
condValue, memOrG, shouldLog, mem.msg,
|
||||||
|
valueStr, gllOff, llOff, condFalse,
|
||||||
|
ll2VSgll, ll2VSll
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue