port from 1.4.4 (rev. 1925 fixed SF# 3483174)
This commit is contained in:
Родитель
d9cf671330
Коммит
801b2485f4
|
@ -167,6 +167,15 @@ class Foundation_API FileChannel: public Channel
|
|||
/// deleted, starting with the oldest. When "none" or empty string are
|
||||
/// supplied, they reset purgeCount to none (no purging).
|
||||
///
|
||||
/// The flush property specifies whether each log message is flushed
|
||||
/// immediately to the log file (which may hurt application performance,
|
||||
/// but ensures that everything is in the log in case of a system crash),
|
||||
// or whether it's allowed to stay in the system's file buffer for some time.
|
||||
/// Valid values are:
|
||||
///
|
||||
/// * true: Every essages is immediately flushed to the log file (default).
|
||||
/// * false: Messages are not immediately flushed to the log file.
|
||||
///
|
||||
/// For a more lightweight file channel class, see SimpleFileChannel.
|
||||
{
|
||||
public:
|
||||
|
@ -205,6 +214,9 @@ public:
|
|||
/// * purgeCount: Maximum number of archived log files before
|
||||
/// files are purged. See the FileChannel class
|
||||
/// for details.
|
||||
/// * flush: Specifies whether messages are immediately
|
||||
/// flushed to the log file. See the FileChannel class
|
||||
/// for details.
|
||||
|
||||
std::string getProperty(const std::string& name) const;
|
||||
/// Returns the value of the property with the given name.
|
||||
|
@ -227,6 +239,7 @@ public:
|
|||
static const std::string PROP_COMPRESS;
|
||||
static const std::string PROP_PURGEAGE;
|
||||
static const std::string PROP_PURGECOUNT;
|
||||
static const std::string PROP_FLUSH;
|
||||
|
||||
protected:
|
||||
~FileChannel();
|
||||
|
@ -235,6 +248,7 @@ protected:
|
|||
void setCompress(const std::string& compress);
|
||||
void setPurgeAge(const std::string& age);
|
||||
void setPurgeCount(const std::string& count);
|
||||
void setFlush(const std::string& flush);
|
||||
void purge();
|
||||
|
||||
private:
|
||||
|
@ -245,6 +259,7 @@ private:
|
|||
bool _compress;
|
||||
std::string _purgeAge;
|
||||
std::string _purgeCount;
|
||||
bool _flush;
|
||||
LogFile* _pFile;
|
||||
RotateStrategy* _pRotateStrategy;
|
||||
ArchiveStrategy* _pArchiveStrategy;
|
||||
|
|
|
@ -68,9 +68,11 @@ public:
|
|||
~LogFile();
|
||||
/// Destroys the LogFile.
|
||||
|
||||
void write(const std::string& text);
|
||||
void write(const std::string& text, bool flush = true);
|
||||
/// Writes the given text to the log file.
|
||||
|
||||
/// If flush is true, the text will be immediately
|
||||
/// flushed to the file.
|
||||
|
||||
UInt64 size() const;
|
||||
/// Returns the current size in bytes of the log file.
|
||||
|
||||
|
@ -85,9 +87,9 @@ public:
|
|||
//
|
||||
// inlines
|
||||
//
|
||||
inline void LogFile::write(const std::string& text)
|
||||
inline void LogFile::write(const std::string& text, bool flush)
|
||||
{
|
||||
writeImpl(text);
|
||||
writeImpl(text, flush);
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -56,7 +56,7 @@ class Foundation_API LogFileImpl
|
|||
public:
|
||||
LogFileImpl(const std::string& path);
|
||||
~LogFileImpl();
|
||||
void writeImpl(const std::string& text);
|
||||
void writeImpl(const std::string& text, bool flush);
|
||||
UInt64 sizeImpl() const;
|
||||
Timestamp creationDateImpl() const;
|
||||
const std::string& pathImpl() const;
|
||||
|
|
|
@ -57,7 +57,7 @@ class Foundation_API LogFileImpl
|
|||
public:
|
||||
LogFileImpl(const std::string& path);
|
||||
~LogFileImpl();
|
||||
void writeImpl(const std::string& text);
|
||||
void writeImpl(const std::string& text, bool flush);
|
||||
UInt64 sizeImpl() const;
|
||||
Timestamp creationDateImpl() const;
|
||||
const std::string& pathImpl() const;
|
||||
|
|
|
@ -56,7 +56,7 @@ class Foundation_API LogFileImpl
|
|||
public:
|
||||
LogFileImpl(const std::string& path);
|
||||
~LogFileImpl();
|
||||
void writeImpl(const std::string& text);
|
||||
void writeImpl(const std::string& text, bool flush);
|
||||
UInt64 sizeImpl() const;
|
||||
Timestamp creationDateImpl() const;
|
||||
const std::string& pathImpl() const;
|
||||
|
|
|
@ -56,7 +56,7 @@ class Foundation_API LogFileImpl
|
|||
public:
|
||||
LogFileImpl(const std::string& path);
|
||||
~LogFileImpl();
|
||||
void writeImpl(const std::string& text);
|
||||
void writeImpl(const std::string& text, bool flush);
|
||||
UInt64 sizeImpl() const;
|
||||
Timestamp creationDateImpl() const;
|
||||
const std::string& pathImpl() const;
|
||||
|
|
|
@ -88,6 +88,16 @@ class Foundation_API SimpleFileChannel: public Channel
|
|||
///
|
||||
/// If no secondary path is specified, the secondary path will
|
||||
/// default to <primaryPath>.1.
|
||||
///
|
||||
/// The flush property specifies whether each log message is flushed
|
||||
/// immediately to the log file (which may hurt application performance,
|
||||
/// but ensures that everything is in the log in case of a system crash),
|
||||
// or whether it's allowed to stay in the system's file buffer for some time.
|
||||
/// Valid values are:
|
||||
///
|
||||
/// * true: Every essages is immediately flushed to the log file (default).
|
||||
/// * false: Messages are not immediately flushed to the log file.
|
||||
///
|
||||
{
|
||||
public:
|
||||
SimpleFileChannel();
|
||||
|
@ -113,6 +123,9 @@ public:
|
|||
/// * secondaryPath: The secondary log file's path.
|
||||
/// * rotation: The log file's rotation mode. See the
|
||||
/// SimpleFileChannel class for details.
|
||||
/// * flush: Specifies whether messages are immediately
|
||||
/// flushed to the log file. See the SimpleFileChannel
|
||||
/// class for details.
|
||||
|
||||
std::string getProperty(const std::string& name) const;
|
||||
/// Returns the value of the property with the given name.
|
||||
|
@ -134,10 +147,12 @@ public:
|
|||
static const std::string PROP_PATH;
|
||||
static const std::string PROP_SECONDARYPATH;
|
||||
static const std::string PROP_ROTATION;
|
||||
static const std::string PROP_FLUSH;
|
||||
|
||||
protected:
|
||||
~SimpleFileChannel();
|
||||
void setRotation(const std::string& rotation);
|
||||
void setFlush(const std::string& flush);
|
||||
void rotate();
|
||||
|
||||
private:
|
||||
|
@ -145,6 +160,7 @@ private:
|
|||
std::string _secondaryPath;
|
||||
std::string _rotation;
|
||||
UInt64 _limit;
|
||||
bool _flush;
|
||||
LogFile* _pFile;
|
||||
FastMutex _mutex;
|
||||
};
|
||||
|
|
|
@ -59,11 +59,13 @@ const std::string FileChannel::PROP_TIMES = "times";
|
|||
const std::string FileChannel::PROP_COMPRESS = "compress";
|
||||
const std::string FileChannel::PROP_PURGEAGE = "purgeAge";
|
||||
const std::string FileChannel::PROP_PURGECOUNT = "purgeCount";
|
||||
const std::string FileChannel::PROP_FLUSH = "flush ";
|
||||
|
||||
|
||||
FileChannel::FileChannel():
|
||||
_times("utc"),
|
||||
_compress(false),
|
||||
_flush(true),
|
||||
_pFile(0),
|
||||
_pRotateStrategy(0),
|
||||
_pArchiveStrategy(new ArchiveByNumberStrategy),
|
||||
|
@ -76,6 +78,7 @@ FileChannel::FileChannel(const std::string& path):
|
|||
_path(path),
|
||||
_times("utc"),
|
||||
_compress(false),
|
||||
_flush(true),
|
||||
_pFile(0),
|
||||
_pRotateStrategy(0),
|
||||
_pArchiveStrategy(new ArchiveByNumberStrategy),
|
||||
|
@ -135,7 +138,7 @@ void FileChannel::log(const Message& msg)
|
|||
// to the new file.
|
||||
_pRotateStrategy->mustRotate(_pFile);
|
||||
}
|
||||
_pFile->write(msg.getText());
|
||||
_pFile->write(msg.getText(), _flush);
|
||||
}
|
||||
|
||||
|
||||
|
@ -165,6 +168,8 @@ void FileChannel::setProperty(const std::string& name, const std::string& value)
|
|||
setPurgeAge(value);
|
||||
else if (name == PROP_PURGECOUNT)
|
||||
setPurgeCount(value);
|
||||
else if (name == PROP_FLUSH)
|
||||
setFlush(value);
|
||||
else
|
||||
Channel::setProperty(name, value);
|
||||
}
|
||||
|
@ -186,6 +191,8 @@ std::string FileChannel::getProperty(const std::string& name) const
|
|||
return _purgeAge;
|
||||
else if (name == PROP_PURGECOUNT)
|
||||
return _purgeCount;
|
||||
else if (name == PROP_FLUSH)
|
||||
return std::string(_flush ? "true" : "false");
|
||||
else
|
||||
return Channel::getProperty(name);
|
||||
}
|
||||
|
@ -347,6 +354,12 @@ void FileChannel::setPurgeAge(const std::string& age)
|
|||
}
|
||||
|
||||
|
||||
void FileChannel::setFlush(const std::string& flush)
|
||||
{
|
||||
_flush = icompare(flush, "true") == 0;
|
||||
}
|
||||
|
||||
|
||||
void FileChannel::setPurgeCount(const std::string& count)
|
||||
{
|
||||
delete _pPurgeStrategy;
|
||||
|
|
|
@ -58,9 +58,13 @@ LogFileImpl::~LogFileImpl()
|
|||
}
|
||||
|
||||
|
||||
void LogFileImpl::writeImpl(const std::string& text)
|
||||
void LogFileImpl::writeImpl(const std::string& text, bool flush)
|
||||
{
|
||||
_str << text << std::endl;
|
||||
_str << text;
|
||||
if (flush)
|
||||
_str << std::endl;
|
||||
else
|
||||
_str << "\n";
|
||||
if (!_str.good()) throw WriteFileException(_path);
|
||||
}
|
||||
|
||||
|
|
|
@ -59,14 +59,17 @@ LogFileImpl::~LogFileImpl()
|
|||
}
|
||||
|
||||
|
||||
void LogFileImpl::writeImpl(const std::string& text)
|
||||
void LogFileImpl::writeImpl(const std::string& text, bool flush)
|
||||
{
|
||||
int rc = fputs(text.c_str(), _file);
|
||||
if (rc == EOF) throw WriteFileException(_path);
|
||||
rc = fputc('\n', _file);
|
||||
if (rc == EOF) throw WriteFileException(_path);
|
||||
rc = fflush(_file);
|
||||
if (rc == EOF) throw WriteFileException(_path);
|
||||
if (flush)
|
||||
{
|
||||
rc = fflush(_file);
|
||||
if (rc == EOF) throw WriteFileException(_path);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -61,7 +61,7 @@ LogFileImpl::~LogFileImpl()
|
|||
}
|
||||
|
||||
|
||||
void LogFileImpl::writeImpl(const std::string& text)
|
||||
void LogFileImpl::writeImpl(const std::string& text, bool flush)
|
||||
{
|
||||
if (INVALID_HANDLE_VALUE == _hFile) createFile();
|
||||
|
||||
|
@ -70,8 +70,11 @@ void LogFileImpl::writeImpl(const std::string& text)
|
|||
if (!res) throw WriteFileException(_path);
|
||||
res = WriteFile(_hFile, "\r\n", 2, &bytesWritten, NULL);
|
||||
if (!res) throw WriteFileException(_path);
|
||||
res = FlushFileBuffers(_hFile);
|
||||
if (!res) throw WriteFileException(_path);
|
||||
if (flush)
|
||||
{
|
||||
res = FlushFileBuffers(_hFile);
|
||||
if (!res) throw WriteFileException(_path);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -62,7 +62,7 @@ LogFileImpl::~LogFileImpl()
|
|||
}
|
||||
|
||||
|
||||
void LogFileImpl::writeImpl(const std::string& text)
|
||||
void LogFileImpl::writeImpl(const std::string& text, bool flush)
|
||||
{
|
||||
if (INVALID_HANDLE_VALUE == _hFile) createFile();
|
||||
|
||||
|
@ -71,8 +71,11 @@ void LogFileImpl::writeImpl(const std::string& text)
|
|||
if (!res) throw WriteFileException(_path);
|
||||
res = WriteFile(_hFile, "\r\n", 2, &bytesWritten, NULL);
|
||||
if (!res) throw WriteFileException(_path);
|
||||
res = FlushFileBuffers(_hFile);
|
||||
if (!res) throw WriteFileException(_path);
|
||||
if (flush)
|
||||
{
|
||||
res = FlushFileBuffers(_hFile);
|
||||
if (!res) throw WriteFileException(_path);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -40,6 +40,7 @@
|
|||
#include "Poco/Message.h"
|
||||
#include "Poco/Exception.h"
|
||||
#include "Poco/Ascii.h"
|
||||
#include "Poco/String.h"
|
||||
|
||||
|
||||
namespace Poco {
|
||||
|
@ -48,10 +49,12 @@ namespace Poco {
|
|||
const std::string SimpleFileChannel::PROP_PATH = "path";
|
||||
const std::string SimpleFileChannel::PROP_SECONDARYPATH = "secondaryPath";
|
||||
const std::string SimpleFileChannel::PROP_ROTATION = "rotation";
|
||||
const std::string SimpleFileChannel::PROP_FLUSH = "flush";
|
||||
|
||||
|
||||
SimpleFileChannel::SimpleFileChannel():
|
||||
_limit(0),
|
||||
_flush(true),
|
||||
_pFile(0)
|
||||
{
|
||||
}
|
||||
|
@ -61,6 +64,7 @@ SimpleFileChannel::SimpleFileChannel(const std::string& path):
|
|||
_path(path),
|
||||
_secondaryPath(path + ".0"),
|
||||
_limit(0),
|
||||
_flush(true),
|
||||
_pFile(0)
|
||||
{
|
||||
}
|
||||
|
@ -111,7 +115,7 @@ void SimpleFileChannel::log(const Message& msg)
|
|||
{
|
||||
rotate();
|
||||
}
|
||||
_pFile->write(msg.getText());
|
||||
_pFile->write(msg.getText(), _flush);
|
||||
}
|
||||
|
||||
|
||||
|
@ -129,6 +133,8 @@ void SimpleFileChannel::setProperty(const std::string& name, const std::string&
|
|||
_secondaryPath = value;
|
||||
else if (name == PROP_ROTATION)
|
||||
setRotation(value);
|
||||
else if (name == PROP_FLUSH)
|
||||
setFlush(value);
|
||||
else
|
||||
Channel::setProperty(name, value);
|
||||
}
|
||||
|
@ -142,6 +148,8 @@ std::string SimpleFileChannel::getProperty(const std::string& name) const
|
|||
return _secondaryPath;
|
||||
else if (name == PROP_ROTATION)
|
||||
return _rotation;
|
||||
else if (name == PROP_FLUSH)
|
||||
return std::string(_flush ? "true" : "false");
|
||||
else
|
||||
return Channel::getProperty(name);
|
||||
}
|
||||
|
@ -202,6 +210,12 @@ void SimpleFileChannel::setRotation(const std::string& rotation)
|
|||
}
|
||||
|
||||
|
||||
void SimpleFileChannel::setFlush(const std::string& flush)
|
||||
{
|
||||
_flush = icompare(flush, "true") == 0;
|
||||
}
|
||||
|
||||
|
||||
void SimpleFileChannel::rotate()
|
||||
{
|
||||
std::string newPath;
|
||||
|
|
Загрузка…
Ссылка в новой задаче