mirror of
https://github.com/pocoproject/poco.git
synced 2025-10-15 07:14:46 +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.
|
||||
///
|
||||
/// 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
|
||||
/// are supported:
|
||||
///
|
||||
@@ -154,6 +154,7 @@ class Foundation_API FileChannel: public Channel
|
||||
///
|
||||
/// The purgeAge property can have the following values:
|
||||
///
|
||||
/// * "none" or "" no purging
|
||||
/// * <n> [seconds] the maximum age is <n> seconds.
|
||||
/// * <n> minutes: the maximum age is <n> minutes.
|
||||
/// * <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> months: the maximum age is <n> months, where a month has 30 days.
|
||||
///
|
||||
/// The purgeCount property has an integer value that
|
||||
/// specifies the maximum number of archived log files.
|
||||
/// If the number is exceeded, archived log files are
|
||||
/// deleted, starting with the oldest.
|
||||
/// The purgeCount property has an integer value that specifies the maximum number
|
||||
/// of archived log files. If the number is exceeded, archived log files are
|
||||
/// deleted, starting with the oldest. When "none" or empty string are
|
||||
/// supplied, they reset purgeCount to none (no purging).
|
||||
///
|
||||
/// 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)
|
||||
{
|
||||
std::string::const_iterator it = age.begin();
|
||||
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 end = age.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;
|
||||
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;
|
||||
while (it != end && Ascii::isAlpha(*it)) unit += *it++;
|
||||
while (it != end && Ascii::isAlpha(*it))
|
||||
unit += *it++;
|
||||
|
||||
Timespan::TimeDiff factor = Timespan::SECONDS;
|
||||
if (unit == "minutes")
|
||||
@@ -321,26 +335,43 @@ void FileChannel::setPurgeAge(const std::string& age)
|
||||
else if (unit == "weeks")
|
||||
factor = 7*Timespan::DAYS;
|
||||
else if (unit == "months")
|
||||
factor = 30*Timespan::DAYS;
|
||||
factor = 30 * Timespan::DAYS;
|
||||
else if (unit != "seconds")
|
||||
throw InvalidArgumentException("purgeAge", age);
|
||||
|
||||
delete _pPurgeStrategy;
|
||||
_pPurgeStrategy = new PurgeByAgeStrategy(Timespan(factor*n));
|
||||
if (0 == n)
|
||||
throw InvalidArgumentException("Zero is not valid purge age.");
|
||||
|
||||
_pPurgeStrategy = new PurgeByAgeStrategy(Timespan(factor * n));
|
||||
_purgeAge = age;
|
||||
}
|
||||
|
||||
|
||||
void FileChannel::setPurgeCount(const std::string& count)
|
||||
{
|
||||
std::string::const_iterator it = count.begin();
|
||||
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;
|
||||
_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 end = count.end();
|
||||
|
||||
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);
|
||||
_purgeCount = count;
|
||||
}
|
||||
|
@@ -72,9 +72,14 @@ public:
|
||||
static CppUnit::Test* suite();
|
||||
|
||||
private:
|
||||
template <class D> std::string rotation(TimeRotation rtype) const;
|
||||
void remove(const std::string& baseName);
|
||||
std::string filename() const;
|
||||
template <class D> std::string rotation(TimeRotation rtype) const;
|
||||
void remove(const std::string& baseName);
|
||||
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