mirror of
https://github.com/pocoproject/poco.git
synced 2025-04-24 17:18:32 +02:00
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:
parent
3bacb6696f
commit
e836f91d90
@ -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;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
@ -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;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user