Merge pull request #152 from denizzzka/logger_args_check

Logger: avoid formatting for strings without additional args
This commit is contained in:
Sönke Ludwig 2019-04-26 09:43:58 +02:00 committed by GitHub
commit d96c5cb594
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -804,13 +804,17 @@ package void initializeLogModule()
private nothrow void doLog(S, T...)(LogLevel level, string mod, string func, string file, int line, S fmt, lazy T args) private nothrow void doLog(S, T...)(LogLevel level, string mod, string func, string file, int line, S fmt, lazy T args)
{ {
try { try {
auto args_copy = args; static if(T.length != 0)
auto args_copy = args;
foreach (l; getLoggers()) foreach (l; getLoggers())
if (l.minLevel <= level) { // WARNING: TYPE SYSTEM HOLE: accessing field of shared class! if (l.minLevel <= level) { // WARNING: TYPE SYSTEM HOLE: accessing field of shared class!
auto ll = l.lock(); auto ll = l.lock();
auto rng = LogOutputRange(ll, file, line, level); auto rng = LogOutputRange(ll, file, line, level);
/*() @trusted {*/ rng.formattedWrite(fmt, args_copy); //} (); // formattedWrite is not @safe at least up to 2.068.0 static if(T.length != 0)
/*() @trusted {*/ rng.formattedWrite(fmt, args_copy); //} (); // formattedWrite is not @safe at least up to 2.068.0
else
rng.put(fmt);
rng.finalize(); rng.finalize();
} }
} catch(Exception e) debug assert(false, e.msg); } catch(Exception e) debug assert(false, e.msg);