diff --git a/src/api/logging.cpp b/src/api/logging.cpp index 4e07a6b9f..e0690c298 100644 --- a/src/api/logging.cpp +++ b/src/api/logging.cpp @@ -236,6 +236,12 @@ void Logger::History::dump_messages(Data &buffer) { // Logger::StdoutTarget // +Logger::StdoutTarget::~StdoutTarget() { + if (m_file_stream) { + m_file_stream->close(false); + } +} + void Logger::StdoutTarget::write(const Data &msg) { if (Net::current().is_running()) { if (!m_file_stream) m_file_stream = FileStream::make(false, m_f, &s_dp_stdout); diff --git a/src/api/logging.hpp b/src/api/logging.hpp index 0e903e32e..94919297f 100644 --- a/src/api/logging.hpp +++ b/src/api/logging.hpp @@ -83,6 +83,7 @@ class Logger : public pjs::ObjectTemplate { class StdoutTarget : public Target { public: StdoutTarget(FILE *f) : m_f(f) {} + ~StdoutTarget(); private: virtual void write(const Data &msg) override; diff --git a/src/fstream.cpp b/src/fstream.cpp index e9f1b73b1..33b8bde6b 100644 --- a/src/fstream.cpp +++ b/src/fstream.cpp @@ -49,9 +49,13 @@ FileStream::FileStream(bool read, FILE *f, Data::Producer *dp) if (read) this->read(); } -void FileStream::close() { +void FileStream::close(bool close_fd) { std::error_code ec; - m_stream.close(ec); + if (close_fd) { + m_stream.close(ec); + } else { + m_stream.release(); + } if (m_receiving_state == PAUSED) { m_receiving_state = RECEIVING; @@ -65,7 +69,7 @@ void FileStream::close() { } if (m_f) { - fclose(m_f); + if (close_fd) fclose(m_f); m_f = nullptr; } } diff --git a/src/fstream.hpp b/src/fstream.hpp index 91b2b03db..f50c6edef 100644 --- a/src/fstream.hpp +++ b/src/fstream.hpp @@ -58,7 +58,7 @@ class FileStream : auto fd() const -> int { return m_fd; } void set_buffer_limit(size_t size) { m_buffer_limit = size; } - void close(); + void close(bool close_fd = true); private: FileStream(bool read, int fd, Data::Producer *dp);