Bug 15771 – FileLogger should create the output directory if it does not exist

Status
RESOLVED
Resolution
FIXED
Severity
enhancement
Priority
P1
Component
phobos
Product
D
Version
D2
Platform
All
OS
All
Creation time
2016-03-06T09:47:32Z
Last change time
2018-01-05T13:30:17Z
Assigned to
No Owner
Creator
Minas

Comments

Comment #0 by minasm1990 — 2016-03-06T09:47:32Z
Currectly, this throws an exception, because the folder "oops" does not exist. // import std.experimental.logger; void main() { auto logger = new FileLogger("/home/minas/oops/log.txt"); } // std.exception.ErrnoException@std/stdio.d(393): Cannot open file `/home/minas/oops/log.txt' in mode `a' (No such file or directory) The solution is simple: mkdirRecurse("/home/minas/oops/"); However, this is something that the logging system should be doing, not the client programmer. (As an example Java's logback and log4j create the directory structure if it's not there).
Comment #1 by petar.p.kirov — 2016-03-06T12:42:24Z
Perhaps this behavior can be supported by adding an additional flag to the constructor? For example: - this(in string fn, const LogLevel lv = LogLevel.all) + this(in string fn, const LogLevel lv = LogLevel.all, bool makeParentDirectories = false)
Comment #2 by github-bugzilla — 2017-07-12T13:33:07Z
Commits pushed to master at https://github.com/dlang/phobos https://github.com/dlang/phobos/commit/e85381ee42652029a8b1c8d8397aee78c2ae7139 Fix Issue 15771 - FileLogger should create the output directory if it does not exist https://github.com/dlang/phobos/commit/d27a3bf9d53c9b0dd35f70c5060891d68dd6ce6a Merge pull request #5594 from RazvanN7/Issue_15771 Fix Issue 15771 - FileLogger should create the output directory if it does not exist merged-on-behalf-of: Sebastian Wilzbach <[email protected]>
Comment #3 by github-bugzilla — 2017-08-16T13:24:01Z
Commits pushed to stable at https://github.com/dlang/phobos https://github.com/dlang/phobos/commit/e85381ee42652029a8b1c8d8397aee78c2ae7139 Fix Issue 15771 - FileLogger should create the output directory if it does not exist https://github.com/dlang/phobos/commit/d27a3bf9d53c9b0dd35f70c5060891d68dd6ce6a Merge pull request #5594 from RazvanN7/Issue_15771
Comment #4 by github-bugzilla — 2018-01-05T13:30:17Z
Commits pushed to dmd-cxx at https://github.com/dlang/phobos https://github.com/dlang/phobos/commit/e85381ee42652029a8b1c8d8397aee78c2ae7139 Fix Issue 15771 - FileLogger should create the output directory if it does not exist https://github.com/dlang/phobos/commit/d27a3bf9d53c9b0dd35f70c5060891d68dd6ce6a Merge pull request #5594 from RazvanN7/Issue_15771