1 | // |
2 | // PurgeStrategy.h |
3 | // |
4 | // Library: Foundation |
5 | // Package: Logging |
6 | // Module: FileChannel |
7 | // |
8 | // Definition of the PurgeStrategy class. |
9 | // |
10 | // Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH. |
11 | // and Contributors. |
12 | // |
13 | // SPDX-License-Identifier: BSL-1.0 |
14 | // |
15 | |
16 | |
17 | #ifndef Foundation_PurgeStrategy_INCLUDED |
18 | #define Foundation_PurgeStrategy_INCLUDED |
19 | |
20 | |
21 | #include "Poco/Foundation.h" |
22 | #include "Poco/File.h" |
23 | #include "Poco/Timespan.h" |
24 | #include <vector> |
25 | |
26 | |
27 | namespace Poco { |
28 | |
29 | |
30 | class Foundation_API PurgeStrategy |
31 | /// The PurgeStrategy is used by FileChannel |
32 | /// to purge archived log files. |
33 | { |
34 | public: |
35 | PurgeStrategy(); |
36 | virtual ~PurgeStrategy(); |
37 | |
38 | virtual void purge(const std::string& path) = 0; |
39 | /// Purges archived log files. The path to the |
40 | /// current "hot" log file is given. |
41 | /// To find archived log files, look for files |
42 | /// with a name consisting of the given path |
43 | /// plus any suffix (e.g., .1, .20050929081500, .1.gz). |
44 | /// A list of archived files can be obtained by calling |
45 | /// the list() method. |
46 | |
47 | protected: |
48 | void list(const std::string& path, std::vector<File>& files); |
49 | /// Fills the given vector with a list of archived log |
50 | /// files. The path of the current "hot" log file is |
51 | /// given in path. |
52 | /// |
53 | /// All files with the same name as the one given in path, |
54 | /// plus some suffix (e.g., .1, .20050929081500, .1.gz) are |
55 | /// considered archived files. |
56 | |
57 | private: |
58 | PurgeStrategy(const PurgeStrategy&); |
59 | PurgeStrategy& operator = (const PurgeStrategy&); |
60 | }; |
61 | |
62 | |
63 | class Foundation_API PurgeByAgeStrategy: public PurgeStrategy |
64 | /// This purge strategy purges all files that have |
65 | /// exceeded a given age (given in seconds). |
66 | { |
67 | public: |
68 | PurgeByAgeStrategy(const Timespan& age); |
69 | ~PurgeByAgeStrategy(); |
70 | |
71 | void purge(const std::string& path); |
72 | |
73 | private: |
74 | Timespan _age; |
75 | }; |
76 | |
77 | |
78 | class Foundation_API PurgeByCountStrategy: public PurgeStrategy |
79 | /// This purge strategy ensures that a maximum number |
80 | /// of archived files is not exceeded. Files are deleted |
81 | /// based on their age, with oldest files deleted first. |
82 | { |
83 | public: |
84 | PurgeByCountStrategy(int count); |
85 | ~PurgeByCountStrategy(); |
86 | |
87 | void purge(const std::string& path); |
88 | |
89 | private: |
90 | int _count; |
91 | }; |
92 | |
93 | |
94 | } // namespace Poco |
95 | |
96 | |
97 | #endif // Foundation_PurgeStrategy_INCLUDED |
98 | |