diff options
author | orivej <orivej@yandex-team.ru> | 2022-02-10 16:44:49 +0300 |
---|---|---|
committer | Daniil Cherednik <dcherednik@yandex-team.ru> | 2022-02-10 16:44:49 +0300 |
commit | 718c552901d703c502ccbefdfc3c9028d608b947 (patch) | |
tree | 46534a98bbefcd7b1f3faa5b52c138ab27db75b7 /contrib/libs/poco/Foundation/src/RotateStrategy.cpp | |
parent | e9656aae26e0358d5378e5b63dcac5c8dbe0e4d0 (diff) | |
download | ydb-718c552901d703c502ccbefdfc3c9028d608b947.tar.gz |
Restoring authorship annotation for <orivej@yandex-team.ru>. Commit 1 of 2.
Diffstat (limited to 'contrib/libs/poco/Foundation/src/RotateStrategy.cpp')
-rw-r--r-- | contrib/libs/poco/Foundation/src/RotateStrategy.cpp | 226 |
1 files changed, 113 insertions, 113 deletions
diff --git a/contrib/libs/poco/Foundation/src/RotateStrategy.cpp b/contrib/libs/poco/Foundation/src/RotateStrategy.cpp index 0019ff9119..1dfed687f0 100644 --- a/contrib/libs/poco/Foundation/src/RotateStrategy.cpp +++ b/contrib/libs/poco/Foundation/src/RotateStrategy.cpp @@ -1,113 +1,113 @@ -// -// RotateStrategy.cpp -// -// Library: Foundation -// Package: Logging -// Module: FileChannel -// -// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH. -// and Contributors. -// -// SPDX-License-Identifier: BSL-1.0 -// - - -#include "Poco/RotateStrategy.h" -#include "Poco/FileStream.h" -#include "Poco/DateTimeParser.h" -#include "Poco/DateTimeFormatter.h" -#include "Poco/DateTimeFormat.h" - - -namespace Poco { - - -// -// RotateStrategy -// - - -RotateStrategy::RotateStrategy() -{ -} - - -RotateStrategy::~RotateStrategy() -{ -} - - -// -// RotateByIntervalStrategy -// - - -const std::string RotateByIntervalStrategy::ROTATE_TEXT("# Log file created/rotated "); - - -RotateByIntervalStrategy::RotateByIntervalStrategy(const Timespan& span): - _span(span), - _lastRotate(0) -{ - if (span.totalMicroseconds() <= 0) throw InvalidArgumentException("time span must be greater than zero"); -} - - -RotateByIntervalStrategy::~RotateByIntervalStrategy() -{ -} - - -bool RotateByIntervalStrategy::mustRotate(LogFile* pFile) -{ - if (_lastRotate == 0 || pFile->size() == 0) - { - if (pFile->size() != 0) - { - Poco::FileInputStream istr(pFile->path()); - std::string tag; - std::getline(istr, tag); - if (tag.compare(0, ROTATE_TEXT.size(), ROTATE_TEXT) == 0) - { - std::string timestamp(tag, ROTATE_TEXT.size()); - int tzd; - _lastRotate = DateTimeParser::parse(DateTimeFormat::RFC1036_FORMAT, timestamp, tzd).timestamp(); - } - else _lastRotate = pFile->creationDate(); - } - else - { - _lastRotate.update(); - std::string tag(ROTATE_TEXT); - DateTimeFormatter::append(tag, _lastRotate, DateTimeFormat::RFC1036_FORMAT); - pFile->write(tag); - } - } - Timestamp now; - return _span <= now - _lastRotate; -} - - -// -// RotateBySizeStrategy -// - - -RotateBySizeStrategy::RotateBySizeStrategy(UInt64 size): _size(size) -{ - if (size == 0) throw InvalidArgumentException("size must be greater than zero"); -} - - -RotateBySizeStrategy::~RotateBySizeStrategy() -{ -} - - -bool RotateBySizeStrategy::mustRotate(LogFile* pFile) -{ - return pFile->size() >= _size; -} - - -} // namespace Poco +// +// RotateStrategy.cpp +// +// Library: Foundation +// Package: Logging +// Module: FileChannel +// +// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH. +// and Contributors. +// +// SPDX-License-Identifier: BSL-1.0 +// + + +#include "Poco/RotateStrategy.h" +#include "Poco/FileStream.h" +#include "Poco/DateTimeParser.h" +#include "Poco/DateTimeFormatter.h" +#include "Poco/DateTimeFormat.h" + + +namespace Poco { + + +// +// RotateStrategy +// + + +RotateStrategy::RotateStrategy() +{ +} + + +RotateStrategy::~RotateStrategy() +{ +} + + +// +// RotateByIntervalStrategy +// + + +const std::string RotateByIntervalStrategy::ROTATE_TEXT("# Log file created/rotated "); + + +RotateByIntervalStrategy::RotateByIntervalStrategy(const Timespan& span): + _span(span), + _lastRotate(0) +{ + if (span.totalMicroseconds() <= 0) throw InvalidArgumentException("time span must be greater than zero"); +} + + +RotateByIntervalStrategy::~RotateByIntervalStrategy() +{ +} + + +bool RotateByIntervalStrategy::mustRotate(LogFile* pFile) +{ + if (_lastRotate == 0 || pFile->size() == 0) + { + if (pFile->size() != 0) + { + Poco::FileInputStream istr(pFile->path()); + std::string tag; + std::getline(istr, tag); + if (tag.compare(0, ROTATE_TEXT.size(), ROTATE_TEXT) == 0) + { + std::string timestamp(tag, ROTATE_TEXT.size()); + int tzd; + _lastRotate = DateTimeParser::parse(DateTimeFormat::RFC1036_FORMAT, timestamp, tzd).timestamp(); + } + else _lastRotate = pFile->creationDate(); + } + else + { + _lastRotate.update(); + std::string tag(ROTATE_TEXT); + DateTimeFormatter::append(tag, _lastRotate, DateTimeFormat::RFC1036_FORMAT); + pFile->write(tag); + } + } + Timestamp now; + return _span <= now - _lastRotate; +} + + +// +// RotateBySizeStrategy +// + + +RotateBySizeStrategy::RotateBySizeStrategy(UInt64 size): _size(size) +{ + if (size == 0) throw InvalidArgumentException("size must be greater than zero"); +} + + +RotateBySizeStrategy::~RotateBySizeStrategy() +{ +} + + +bool RotateBySizeStrategy::mustRotate(LogFile* pFile) +{ + return pFile->size() >= _size; +} + + +} // namespace Poco |