Skip to content

Commit 0d94621

Browse files
authored
Merge pull request #48 from sile/issue45
Enable flushing for JSON logger
2 parents 37c3fea + 0c60fa7 commit 0d94621

File tree

2 files changed

+16
-7
lines changed

2 files changed

+16
-7
lines changed

src/file.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,10 @@ impl Build for FileLoggerBuilder {
154154
}
155155
#[cfg(feature = "json")]
156156
Format::Json => {
157-
let drain = slog_json::Json::default(self.appender.clone());
157+
let drain = slog_json::Json::new(self.appender.clone())
158+
.set_flush(true)
159+
.add_default_keys()
160+
.build();
158161
self.common.build_with_drain(drain)
159162
}
160163
};

src/terminal.rs

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -103,12 +103,18 @@ impl Build for TerminalLoggerBuilder {
103103
}
104104
#[cfg(feature = "json")]
105105
Format::Json => match self.destination {
106-
Destination::Stdout => self
107-
.common
108-
.build_with_drain(slog_json::Json::default(std::io::stdout())),
109-
Destination::Stderr => self
110-
.common
111-
.build_with_drain(slog_json::Json::default(std::io::stderr())),
106+
Destination::Stdout => self.common.build_with_drain(
107+
slog_json::Json::new(std::io::stdout())
108+
.set_flush(true)
109+
.add_default_keys()
110+
.build(),
111+
),
112+
Destination::Stderr => self.common.build_with_drain(
113+
slog_json::Json::new(std::io::stderr())
114+
.set_flush(true)
115+
.add_default_keys()
116+
.build(),
117+
),
112118
},
113119
};
114120
Ok(logger)

0 commit comments

Comments
 (0)