mirror of
https://github.com/pocoproject/poco.git
synced 2025-10-15 15:16:49 +02:00
FileChannel: added "none" to the PURGE_AGE and PURGE_COUNT
This commit is contained in:
@@ -140,7 +140,7 @@ class Foundation_API FileChannel: public Channel
|
|||||||
/// * local: Rotation strategy is based on local time.
|
/// * local: Rotation strategy is based on local time.
|
||||||
///
|
///
|
||||||
/// Archived log files can be compressed using the gzip compression
|
/// Archived log files can be compressed using the gzip compression
|
||||||
/// method. Compressing can be controlled with the "compress"
|
/// method. Compressing can be controlled with the "compression"
|
||||||
/// property. The following values for the "compress" property
|
/// property. The following values for the "compress" property
|
||||||
/// are supported:
|
/// are supported:
|
||||||
///
|
///
|
||||||
@@ -154,6 +154,7 @@ class Foundation_API FileChannel: public Channel
|
|||||||
///
|
///
|
||||||
/// The purgeAge property can have the following values:
|
/// The purgeAge property can have the following values:
|
||||||
///
|
///
|
||||||
|
/// * "none" or "" no purging
|
||||||
/// * <n> [seconds] the maximum age is <n> seconds.
|
/// * <n> [seconds] the maximum age is <n> seconds.
|
||||||
/// * <n> minutes: the maximum age is <n> minutes.
|
/// * <n> minutes: the maximum age is <n> minutes.
|
||||||
/// * <n> hours: the maximum age is <n> hours.
|
/// * <n> hours: the maximum age is <n> hours.
|
||||||
@@ -161,10 +162,10 @@ class Foundation_API FileChannel: public Channel
|
|||||||
/// * <n> weeks: the maximum age is <n> weeks.
|
/// * <n> weeks: the maximum age is <n> weeks.
|
||||||
/// * <n> months: the maximum age is <n> months, where a month has 30 days.
|
/// * <n> months: the maximum age is <n> months, where a month has 30 days.
|
||||||
///
|
///
|
||||||
/// The purgeCount property has an integer value that
|
/// The purgeCount property has an integer value that specifies the maximum number
|
||||||
/// specifies the maximum number of archived log files.
|
/// of archived log files. If the number is exceeded, archived log files are
|
||||||
/// If the number is exceeded, archived log files are
|
/// deleted, starting with the oldest. When "none" or empty string are
|
||||||
/// deleted, starting with the oldest.
|
/// supplied, they reset purgeCount to none (no purging).
|
||||||
///
|
///
|
||||||
/// For a more lightweight file channel class, see SimpleFileChannel.
|
/// For a more lightweight file channel class, see SimpleFileChannel.
|
||||||
{
|
{
|
||||||
|
@@ -302,14 +302,28 @@ void FileChannel::setCompress(const std::string& compress)
|
|||||||
|
|
||||||
void FileChannel::setPurgeAge(const std::string& age)
|
void FileChannel::setPurgeAge(const std::string& age)
|
||||||
{
|
{
|
||||||
|
delete _pPurgeStrategy;
|
||||||
|
_pPurgeStrategy = 0;
|
||||||
|
_purgeAge = "none";
|
||||||
|
if (age.empty() || 0 == icompare(age, "none"))
|
||||||
|
return;
|
||||||
|
|
||||||
std::string::const_iterator it = age.begin();
|
std::string::const_iterator it = age.begin();
|
||||||
std::string::const_iterator end = age.end();
|
std::string::const_iterator end = age.end();
|
||||||
|
|
||||||
int n = 0;
|
int n = 0;
|
||||||
while (it != end && Ascii::isSpace(*it)) ++it;
|
while (it != end && Ascii::isSpace(*it))
|
||||||
while (it != end && Ascii::isDigit(*it)) { n *= 10; n += *it++ - '0'; }
|
++it;
|
||||||
while (it != end && Ascii::isSpace(*it)) ++it;
|
while (it != end && Ascii::isDigit(*it))
|
||||||
|
{
|
||||||
|
n *= 10;
|
||||||
|
n += *it++ - '0';
|
||||||
|
}
|
||||||
|
while (it != end && Ascii::isSpace(*it))
|
||||||
|
++it;
|
||||||
std::string unit;
|
std::string unit;
|
||||||
while (it != end && Ascii::isAlpha(*it)) unit += *it++;
|
while (it != end && Ascii::isAlpha(*it))
|
||||||
|
unit += *it++;
|
||||||
|
|
||||||
Timespan::TimeDiff factor = Timespan::SECONDS;
|
Timespan::TimeDiff factor = Timespan::SECONDS;
|
||||||
if (unit == "minutes")
|
if (unit == "minutes")
|
||||||
@@ -325,7 +339,9 @@ void FileChannel::setPurgeAge(const std::string& age)
|
|||||||
else if (unit != "seconds")
|
else if (unit != "seconds")
|
||||||
throw InvalidArgumentException("purgeAge", age);
|
throw InvalidArgumentException("purgeAge", age);
|
||||||
|
|
||||||
delete _pPurgeStrategy;
|
if (0 == n)
|
||||||
|
throw InvalidArgumentException("Zero is not valid purge age.");
|
||||||
|
|
||||||
_pPurgeStrategy = new PurgeByAgeStrategy(Timespan(factor * n));
|
_pPurgeStrategy = new PurgeByAgeStrategy(Timespan(factor * n));
|
||||||
_purgeAge = age;
|
_purgeAge = age;
|
||||||
}
|
}
|
||||||
@@ -333,14 +349,29 @@ void FileChannel::setPurgeAge(const std::string& age)
|
|||||||
|
|
||||||
void FileChannel::setPurgeCount(const std::string& count)
|
void FileChannel::setPurgeCount(const std::string& count)
|
||||||
{
|
{
|
||||||
|
delete _pPurgeStrategy;
|
||||||
|
_pPurgeStrategy = 0;
|
||||||
|
_purgeAge = "none";
|
||||||
|
if (count.empty() || 0 == icompare(count, "none"))
|
||||||
|
return;
|
||||||
|
|
||||||
|
int n = 0;
|
||||||
std::string::const_iterator it = count.begin();
|
std::string::const_iterator it = count.begin();
|
||||||
std::string::const_iterator end = count.end();
|
std::string::const_iterator end = count.end();
|
||||||
int n = 0;
|
|
||||||
while (it != end && Ascii::isSpace(*it)) ++it;
|
|
||||||
while (it != end && Ascii::isDigit(*it)) { n *= 10; n += *it++ - '0'; }
|
|
||||||
while (it != end && Ascii::isSpace(*it)) ++it;
|
|
||||||
|
|
||||||
delete _pPurgeStrategy;
|
while (it != end && Ascii::isSpace(*it))
|
||||||
|
++it;
|
||||||
|
while (it != end && Ascii::isDigit(*it))
|
||||||
|
{
|
||||||
|
n *= 10;
|
||||||
|
n += *it++ - '0';
|
||||||
|
}
|
||||||
|
while (it != end && Ascii::isSpace(*it))
|
||||||
|
++it;
|
||||||
|
|
||||||
|
if (0 == n)
|
||||||
|
throw InvalidArgumentException("Zero is not valid purge count.");
|
||||||
|
|
||||||
_pPurgeStrategy = new PurgeByCountStrategy(n);
|
_pPurgeStrategy = new PurgeByCountStrategy(n);
|
||||||
_purgeCount = count;
|
_purgeCount = count;
|
||||||
}
|
}
|
||||||
|
@@ -75,6 +75,11 @@ private:
|
|||||||
template <class D> std::string rotation(TimeRotation rtype) const;
|
template <class D> std::string rotation(TimeRotation rtype) const;
|
||||||
void remove(const std::string& baseName);
|
void remove(const std::string& baseName);
|
||||||
std::string filename() const;
|
std::string filename() const;
|
||||||
|
|
||||||
|
void purgeAge(const std::string& purgeAge);
|
||||||
|
void noPurgeAge(const std::string& purgeAge);
|
||||||
|
void purgeCount(const std::string& pc);
|
||||||
|
void noPurgeCount(const std::string& pc);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user