Log file fix (#1678)

* fix for RotateBySizeStrategy runaway when fstream bad #1676

* fix for LogFile does not recover after write error #1677

* remove unnecesary throw
This commit is contained in:
Aleksandar Fabijanic 2017-04-17 12:47:33 -05:00 committed by GitHub
parent 3bacb6696f
commit e836f91d90
2 changed files with 12 additions and 3 deletions

View File

@ -45,6 +45,7 @@ private:
std::string _path; std::string _path;
mutable Poco::FileOutputStream _str; mutable Poco::FileOutputStream _str;
Timestamp _creationDate; Timestamp _creationDate;
UInt64 _size;
}; };

View File

@ -24,9 +24,10 @@ namespace Poco {
LogFileImpl::LogFileImpl(const std::string& path): LogFileImpl::LogFileImpl(const std::string& path):
_path(path), _path(path),
_str(_path, std::ios::app) _str(_path, std::ios::app),
_size((UInt64) _str.tellp())
{ {
if (sizeImpl() == 0) if (_size == 0)
_creationDate = File(path).getLastModified(); _creationDate = File(path).getLastModified();
else else
_creationDate = File(path).created(); _creationDate = File(path).created();
@ -40,18 +41,25 @@ LogFileImpl::~LogFileImpl()
void LogFileImpl::writeImpl(const std::string& text, bool flush) void LogFileImpl::writeImpl(const std::string& text, bool flush)
{ {
if (!_str.good())
{
_str.close();
_str.open(_path, std::ios::app);
}
if (!_str.good()) throw WriteFileException(_path);
_str << text; _str << text;
if (flush) if (flush)
_str << std::endl; _str << std::endl;
else else
_str << "\n"; _str << "\n";
if (!_str.good()) throw WriteFileException(_path); if (!_str.good()) throw WriteFileException(_path);
_size = (UInt64) _str.tellp();
} }
UInt64 LogFileImpl::sizeImpl() const UInt64 LogFileImpl::sizeImpl() const
{ {
return (UInt64) _str.tellp(); return _size;
} }