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