summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--mullvad-daemon/src/logging.rs10
1 files changed, 9 insertions, 1 deletions
diff --git a/mullvad-daemon/src/logging.rs b/mullvad-daemon/src/logging.rs
index 4f4869d6e6..2ef62ad8cb 100644
--- a/mullvad-daemon/src/logging.rs
+++ b/mullvad-daemon/src/logging.rs
@@ -6,6 +6,7 @@ use chrono;
use log;
use std::fmt;
+use std::fs;
use std::io;
use std::path::PathBuf;
@@ -13,7 +14,11 @@ error_chain! {
errors {
WriteFileError(path: PathBuf) {
description("Unable to open log file for writing")
- display("Unable to open log file for writing: {}", path.to_string_lossy())
+ display("Unable to open log file for writing: {}", path.display())
+ }
+ CreateDirError(path: PathBuf) {
+ description("Unable to create directory for log")
+ display("Unable to create directory for log: {}", path.display())
}
}
foreign_links {
@@ -70,6 +75,9 @@ pub fn init_logger(
top_dispatcher = top_dispatcher.chain(stdout_dispatcher);
if let Some(ref log_file) = log_file {
+ if let Some(parent) = log_file.parent() {
+ fs::create_dir_all(parent).chain_err(|| ErrorKind::CreateDirError(parent.to_owned()))?;
+ }
let file_formatter = Formatter {
output_timestamp: true,
output_color: false,