Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix Issue 15517: std.experimental.logger: using 'sharedLog' to change to file logging for default logger does not work #5371

Merged
merged 1 commit into from May 29, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
48 changes: 48 additions & 0 deletions std/experimental/logger/core.d
Expand Up @@ -3144,3 +3144,51 @@ private void trustedStore(T)(ref shared T dst, ref T src) @trusted
tl.log("123456789"d);
assert(tl.msg == "123456789");
}

// Issue 15517
@system unittest
{
import std.stdio : File;
import std.string : indexOf;
import std.file : exists, remove;

string fn = "logfile.log";
if (exists(fn))
{
remove(fn);
}

auto oldShared = sharedLog;
scope(exit)
{
sharedLog = oldShared;
if (exists(fn))
{
remove(fn);
}
}

auto ts = [ "Test log 1", "Test log 2", "Test log 3"];

auto fl = new FileLogger(fn);
sharedLog = fl;
assert(exists(fn));

foreach (t; ts)
{
log(t);
}

auto f = File(fn);
auto l = f.byLine();
assert(!l.empty);
size_t idx;
foreach (it; l)
{
assert(it.indexOf(ts[idx]) != -1, it);
++idx;
}

assert(exists(fn));
fl.file.close();
}