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/include/Poco/ArchiveStrategy.h | |
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/include/Poco/ArchiveStrategy.h')
-rw-r--r-- | contrib/libs/poco/Foundation/include/Poco/ArchiveStrategy.h | 292 |
1 files changed, 146 insertions, 146 deletions
diff --git a/contrib/libs/poco/Foundation/include/Poco/ArchiveStrategy.h b/contrib/libs/poco/Foundation/include/Poco/ArchiveStrategy.h index e04605f38a..28a95654a1 100644 --- a/contrib/libs/poco/Foundation/include/Poco/ArchiveStrategy.h +++ b/contrib/libs/poco/Foundation/include/Poco/ArchiveStrategy.h @@ -1,146 +1,146 @@ -// -// ArchiveStrategy.h -// -// Library: Foundation -// Package: Logging -// Module: FileChannel -// -// Definition of the ArchiveStrategy class and subclasses. -// -// Copyright (c) 2004-2008, Applied Informatics Software Engineering GmbH. -// and Contributors. -// -// SPDX-License-Identifier: BSL-1.0 -// - - -#ifndef Foundation_ArchiveStrategy_INCLUDED -#define Foundation_ArchiveStrategy_INCLUDED - - -#include "Poco/Foundation.h" -#include "Poco/LogFile.h" -#include "Poco/File.h" -#include "Poco/DateTimeFormatter.h" -#include "Poco/NumberFormatter.h" - - -namespace Poco { - - -class ArchiveCompressor; - - -class Foundation_API ArchiveStrategy - /// The ArchiveStrategy is used by FileChannel - /// to rename a rotated log file for archiving. - /// - /// Archived files can be automatically compressed, - /// using the gzip file format. -{ -public: - ArchiveStrategy(); - virtual ~ArchiveStrategy(); - - virtual LogFile* archive(LogFile* pFile) = 0; - /// Renames the given log file for archiving - /// and creates and returns a new log file. - /// The given LogFile object is deleted. - - void compress(bool flag = true); - /// Enables or disables compression of archived files. - -protected: - void moveFile(const std::string& oldName, const std::string& newName); - bool exists(const std::string& name); - -private: - ArchiveStrategy(const ArchiveStrategy&); - ArchiveStrategy& operator = (const ArchiveStrategy&); - - bool _compress; - ArchiveCompressor* _pCompressor; -}; - - -class Foundation_API ArchiveByNumberStrategy: public ArchiveStrategy - /// A monotonic increasing number is appended to the - /// log file name. The most recent archived file - /// always has the number zero. -{ -public: - ArchiveByNumberStrategy(); - ~ArchiveByNumberStrategy(); - LogFile* archive(LogFile* pFile); -}; - - -template <class DT> -class ArchiveByTimestampStrategy: public ArchiveStrategy - /// A timestamp (YYYYMMDDhhmmssiii) is appended to archived - /// log files. -{ -public: - ArchiveByTimestampStrategy() - { - } - - ~ArchiveByTimestampStrategy() - { - } - - LogFile* archive(LogFile* pFile) - /// Archives the file by appending the current timestamp to the - /// file name. If the new file name exists, additionally a monotonic - /// increasing number is appended to the log file name. - { - std::string path = pFile->path(); - delete pFile; - std::string archPath = path; - archPath.append("."); - DateTimeFormatter::append(archPath, DT().timestamp(), "%Y%m%d%H%M%S%i"); - - if (exists(archPath)) archiveByNumber(archPath); - else moveFile(path, archPath); - - return new LogFile(path); - } - -private: - void archiveByNumber(const std::string& basePath) - /// A monotonic increasing number is appended to the - /// log file name. The most recent archived file - /// always has the number zero. - { - int n = -1; - std::string path; - do - { - path = basePath; - path.append("."); - NumberFormatter::append(path, ++n); - } - while (exists(path)); - - while (n >= 0) - { - std::string oldPath = basePath; - if (n > 0) - { - oldPath.append("."); - NumberFormatter::append(oldPath, n - 1); - } - std::string newPath = basePath; - newPath.append("."); - NumberFormatter::append(newPath, n); - moveFile(oldPath, newPath); - --n; - } - } -}; - - -} // namespace Poco - - -#endif // Foundation_ArchiveStrategy_INCLUDED +// +// ArchiveStrategy.h +// +// Library: Foundation +// Package: Logging +// Module: FileChannel +// +// Definition of the ArchiveStrategy class and subclasses. +// +// Copyright (c) 2004-2008, Applied Informatics Software Engineering GmbH. +// and Contributors. +// +// SPDX-License-Identifier: BSL-1.0 +// + + +#ifndef Foundation_ArchiveStrategy_INCLUDED +#define Foundation_ArchiveStrategy_INCLUDED + + +#include "Poco/Foundation.h" +#include "Poco/LogFile.h" +#include "Poco/File.h" +#include "Poco/DateTimeFormatter.h" +#include "Poco/NumberFormatter.h" + + +namespace Poco { + + +class ArchiveCompressor; + + +class Foundation_API ArchiveStrategy + /// The ArchiveStrategy is used by FileChannel + /// to rename a rotated log file for archiving. + /// + /// Archived files can be automatically compressed, + /// using the gzip file format. +{ +public: + ArchiveStrategy(); + virtual ~ArchiveStrategy(); + + virtual LogFile* archive(LogFile* pFile) = 0; + /// Renames the given log file for archiving + /// and creates and returns a new log file. + /// The given LogFile object is deleted. + + void compress(bool flag = true); + /// Enables or disables compression of archived files. + +protected: + void moveFile(const std::string& oldName, const std::string& newName); + bool exists(const std::string& name); + +private: + ArchiveStrategy(const ArchiveStrategy&); + ArchiveStrategy& operator = (const ArchiveStrategy&); + + bool _compress; + ArchiveCompressor* _pCompressor; +}; + + +class Foundation_API ArchiveByNumberStrategy: public ArchiveStrategy + /// A monotonic increasing number is appended to the + /// log file name. The most recent archived file + /// always has the number zero. +{ +public: + ArchiveByNumberStrategy(); + ~ArchiveByNumberStrategy(); + LogFile* archive(LogFile* pFile); +}; + + +template <class DT> +class ArchiveByTimestampStrategy: public ArchiveStrategy + /// A timestamp (YYYYMMDDhhmmssiii) is appended to archived + /// log files. +{ +public: + ArchiveByTimestampStrategy() + { + } + + ~ArchiveByTimestampStrategy() + { + } + + LogFile* archive(LogFile* pFile) + /// Archives the file by appending the current timestamp to the + /// file name. If the new file name exists, additionally a monotonic + /// increasing number is appended to the log file name. + { + std::string path = pFile->path(); + delete pFile; + std::string archPath = path; + archPath.append("."); + DateTimeFormatter::append(archPath, DT().timestamp(), "%Y%m%d%H%M%S%i"); + + if (exists(archPath)) archiveByNumber(archPath); + else moveFile(path, archPath); + + return new LogFile(path); + } + +private: + void archiveByNumber(const std::string& basePath) + /// A monotonic increasing number is appended to the + /// log file name. The most recent archived file + /// always has the number zero. + { + int n = -1; + std::string path; + do + { + path = basePath; + path.append("."); + NumberFormatter::append(path, ++n); + } + while (exists(path)); + + while (n >= 0) + { + std::string oldPath = basePath; + if (n > 0) + { + oldPath.append("."); + NumberFormatter::append(oldPath, n - 1); + } + std::string newPath = basePath; + newPath.append("."); + NumberFormatter::append(newPath, n); + moveFile(oldPath, newPath); + --n; + } + } +}; + + +} // namespace Poco + + +#endif // Foundation_ArchiveStrategy_INCLUDED |