diff options
author | Henrik Edin <henrik.edin@mongodb.com> | 2020-03-19 13:07:31 -0400 |
---|---|---|
committer | Evergreen Agent <no-reply@evergreen.mongodb.com> | 2020-03-19 19:58:39 +0000 |
commit | 6f454fc655dddf3486c4e551004fbb9becb4cb4d (patch) | |
tree | fbe33794962732b9807bea461b32897d20b628f7 /src/mongo/logv2 | |
parent | b133bc9931e419264193cc641fe7c9342c4d901b (diff) | |
download | mongo-6f454fc655dddf3486c4e551004fbb9becb4cb4d.tar.gz |
SERVER-45605 Write newline when opening existing log file in append mode.
This should ensure that the first line written is always parsable.
Diffstat (limited to 'src/mongo/logv2')
-rw-r--r-- | src/mongo/logv2/file_rotate_sink.cpp | 8 |
1 files changed, 6 insertions, 2 deletions
diff --git a/src/mongo/logv2/file_rotate_sink.cpp b/src/mongo/logv2/file_rotate_sink.cpp index 3461207030b..941ee7ae7f4 100644 --- a/src/mongo/logv2/file_rotate_sink.cpp +++ b/src/mongo/logv2/file_rotate_sink.cpp @@ -48,13 +48,17 @@ using stream_t = std::ofstream; StatusWith<boost::shared_ptr<stream_t>> openFile(const std::string& filename, bool append) { std::ios_base::openmode mode = std::ios_base::out; - if (append) + bool exists = false; + if (append) { mode |= std::ios_base::app; - else + exists = boost::filesystem::exists(filename); + } else mode |= std::ios_base::trunc; auto file = boost::make_shared<stream_t>(filename, mode); if (file->fail()) return Status(ErrorCodes::FileNotOpen, fmt::format("Failed to open {}", filename)); + if (append && exists) + file->put('\n'); return file; } } // namespace |