From 9da11c44ed414cc66f04d5da123695c6a5760e46 Mon Sep 17 00:00:00 2001 From: Sandip Patel Date: Mon, 19 Aug 2019 11:40:28 +0530 Subject: [PATCH] Fixed log appending issue. --- include/fc/io/fstream.hpp | 5 +++-- src/filesystem.cpp | 2 +- src/io/fstream.cpp | 6 +++--- src/log/file_appender.cpp | 7 ++----- 4 files changed, 9 insertions(+), 11 deletions(-) diff --git a/include/fc/io/fstream.hpp b/include/fc/io/fstream.hpp index 8344ce9..d2c441c 100644 --- a/include/fc/io/fstream.hpp +++ b/include/fc/io/fstream.hpp @@ -2,6 +2,7 @@ #include #include #include +#include namespace fc { class path; @@ -9,10 +10,10 @@ namespace fc { public: enum mode { out, binary }; ofstream(); - ofstream( const fc::path& file, int m = binary ); + ofstream( const fc::path& file, std::ios_base::openmode m = std::ios_base::out | std::ios_base::binary ); ~ofstream(); - void open( const fc::path& file, int m = binary ); + void open( const fc::path& file, std::ios_base::openmode m = std::ios_base::out | std::ios_base::binary ); size_t writesome( const char* buf, size_t len ); size_t writesome(const std::shared_ptr& buffer, size_t len, size_t offset); void put( char c ); diff --git a/src/filesystem.cpp b/src/filesystem.cpp index a590065..249e6d2 100644 --- a/src/filesystem.cpp +++ b/src/filesystem.cpp @@ -368,7 +368,7 @@ namespace fc { } if (create) { - fc::ofstream ofs(*_path, fc::ofstream::out | fc::ofstream::binary); + fc::ofstream ofs(*_path, std::ios_base::out | std::ios_base::binary); ofs.close(); } } diff --git a/src/io/fstream.cpp b/src/io/fstream.cpp index a40bbeb..031026b 100644 --- a/src/io/fstream.cpp +++ b/src/io/fstream.cpp @@ -23,13 +23,13 @@ namespace fc { ofstream::ofstream() :my( new impl() ){} - ofstream::ofstream( const fc::path& file, int m ) + ofstream::ofstream( const fc::path& file, std::ios_base::openmode m ) :my( new impl() ) { this->open( file, m ); } ofstream::~ofstream(){} - void ofstream::open( const fc::path& file, int m ) { + void ofstream::open( const fc::path& file, std::ios_base::openmode m ) { const boost::filesystem::path& bfp = file; - my->ofs.open( bfp, std::ios::binary ); + my->ofs.open( bfp, std::ios_base::out | std::ios_base::binary | m ); } size_t ofstream::writesome( const char* buf, size_t len ) { my->ofs.write(buf,len); diff --git a/src/log/file_appender.cpp b/src/log/file_appender.cpp index 204686a..ffbd6eb 100644 --- a/src/log/file_appender.cpp +++ b/src/log/file_appender.cpp @@ -71,7 +71,7 @@ namespace fc { _compression_thread.reset( new thread( "compression") ); #endif - _rotation_task = async( [this]() { rotate_files( true ); }, "rotate_files(1)" ); + _rotation_task = fc::async( [this]() { rotate_files( true ); }, "rotate_files(1)" ); } } @@ -112,10 +112,7 @@ namespace fc { out.close(); } remove_all(link_filename); // on windows, you can't delete the link while the underlying file is opened for writing - if( fc::exists( log_filename ) ) - out.open( log_filename, std::ios_base::out | std::ios_base::app ); - else - out.open( log_filename, std::ios_base::out | std::ios_base::app); + out.open( log_filename, std::ios_base::out | std::ios_base::app ); create_hard_link(log_filename, link_filename); }