Skip to content

Commit

Permalink
append instead of truncate when opening new files
Browse files Browse the repository at this point in the history
  • Loading branch information
gabime committed Dec 19, 2014
1 parent 92f2b75 commit fcd1fc0
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
10 changes: 5 additions & 5 deletions include/spdlog/details/file_helper.h
Original file line number Diff line number Diff line change
Expand Up @@ -63,15 +63,15 @@ class file_helper
}


void open(const std::string& fname)
void open(const std::string& fname, bool truncate=false)
{

close();

const char* mode = truncate ? "wb" : "ab";
_filename = fname;
for (int tries = 0; tries < open_tries; ++tries)
{
if(!os::fopen_s(&_fd, fname, "wb"))
if(!os::fopen_s(&_fd, fname, mode))
return;

std::this_thread::sleep_for(std::chrono::milliseconds(open_interval));
Expand All @@ -80,11 +80,11 @@ class file_helper
throw spdlog_ex("Failed opening file " + fname + " for writing");
}

void reopen()
void reopen(bool truncate)
{
if(_filename.empty())
throw spdlog_ex("Failed re opening file - was not opened before");
open(_filename);
open(_filename, truncate);

}

Expand Down
2 changes: 1 addition & 1 deletion include/spdlog/sinks/file_sinks.h
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ class rotating_file_sink : public base_sink<Mutex>
throw spdlog_ex("rotating_file_sink: failed renaming " + src + " to " + target);
}
}
_file_helper.reopen();
_file_helper.reopen(true);
}
std::string _base_filename;
std::string _extension;
Expand Down

0 comments on commit fcd1fc0

Please sign in to comment.