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

Allow new shared FileLogger() #8783

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from 1 commit
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
18 changes: 15 additions & 3 deletions std/logger/filelogger.d
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ class FileLogger : Logger
auto l3 = new FileLogger("logFile", LogLevel.fatal, CreateFolder.yes);
-------------
*/
this(const string fn, const LogLevel lv = LogLevel.all) @safe
this(this This)(const string fn, const LogLevel lv = LogLevel.all)
{
this(fn, lv, CreateFolder.yes);
}
Expand All @@ -63,7 +63,7 @@ class FileLogger : Logger
auto l2 = new FileLogger(file, LogLevel.fatal);
-------------
*/
this(const string fn, const LogLevel lv, CreateFolder createFileNameFolder) @safe
this(this This)(const string fn, const LogLevel lv, CreateFolder createFileNameFolder)
{
import std.file : exists, mkdirRecurse;
import std.path : dirName;
Expand All @@ -80,7 +80,10 @@ class FileLogger : Logger
" created in '", d,"' could not be created."));
}

this.file_.open(this.filename, "a");
static if (is(This == shared))
() @trusted { (cast() this.file_).open(this.filename, "a"); }();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just do this all the time? Then no need to template the constructor, add a comment about why.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The constructor still needs to be templated, though.

else
this.file_.open(this.filename, "a");
}

/** A constructor for the `FileLogger` Logger that takes a reference to
Expand Down Expand Up @@ -270,3 +273,12 @@ class FileLogger : Logger
assert(tl !is null);
stdThreadLocalLog.logLevel = LogLevel.all;
}

@safe unittest
{
// we don't need to actually run the code, only make sure
// it compiles
static _() {
auto l = new shared FileLogger("");
}
}