/src/logging-log4cxx/src/main/include/log4cxx/rolling/rollingpolicybase.h
Line | Count | Source |
1 | | /* |
2 | | * Licensed to the Apache Software Foundation (ASF) under one or more |
3 | | * contributor license agreements. See the NOTICE file distributed with |
4 | | * this work for additional information regarding copyright ownership. |
5 | | * The ASF licenses this file to You under the Apache License, Version 2.0 |
6 | | * (the "License"); you may not use this file except in compliance with |
7 | | * the License. You may obtain a copy of the License at |
8 | | * |
9 | | * http://www.apache.org/licenses/LICENSE-2.0 |
10 | | * |
11 | | * Unless required by applicable law or agreed to in writing, software |
12 | | * distributed under the License is distributed on an "AS IS" BASIS, |
13 | | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
14 | | * See the License for the specific language governing permissions and |
15 | | * limitations under the License. |
16 | | */ |
17 | | |
18 | | #if !defined(_LOG4CXX_ROLLING_ROLLING_POLICY_BASE_H) |
19 | | #define _LOG4CXX_ROLLING_ROLLING_POLICY_BASE_H |
20 | | |
21 | | #include <log4cxx/helpers/object.h> |
22 | | #include <log4cxx/logger.h> |
23 | | #include <log4cxx/logmanager.h> |
24 | | #include <log4cxx/rolling/rollingpolicy.h> |
25 | | #include <log4cxx/pattern/patternconverter.h> |
26 | | #include <log4cxx/pattern/formattinginfo.h> |
27 | | #include <log4cxx/pattern/patternparser.h> |
28 | | |
29 | | namespace LOG4CXX_NS |
30 | | { |
31 | | namespace rolling |
32 | | { |
33 | | LOG4CXX_LIST_DEF(PatternConverterList, LOG4CXX_NS::pattern::PatternConverterPtr); |
34 | | LOG4CXX_LIST_DEF(FormattingInfoList, LOG4CXX_NS::pattern::FormattingInfoPtr); |
35 | | |
36 | | /** |
37 | | * Implements methods common to most, it not all, rolling |
38 | | * policies. |
39 | | * |
40 | | * |
41 | | * |
42 | | */ |
43 | | class LOG4CXX_EXPORT RollingPolicyBase : |
44 | | public virtual RollingPolicy, |
45 | | public virtual helpers::Object |
46 | | { |
47 | | protected: |
48 | | DECLARE_ABSTRACT_LOG4CXX_OBJECT(RollingPolicyBase) |
49 | 525 | BEGIN_LOG4CXX_CAST_MAP() |
50 | 525 | LOG4CXX_CAST_ENTRY(RollingPolicy) |
51 | 525 | LOG4CXX_CAST_ENTRY(spi::OptionHandler) |
52 | 525 | END_LOG4CXX_CAST_MAP() |
53 | | |
54 | | LOG4CXX_DECLARE_PRIVATE_MEMBER_PTR(RollingPolicyBasePrivate, m_priv) |
55 | | |
56 | | public: |
57 | | RollingPolicyBase(); |
58 | | virtual ~RollingPolicyBase(); |
59 | | |
60 | | /** |
61 | | \copybrief RollingPolicy::activateOptions() |
62 | | |
63 | | Logs a warning if FileNamePattern is not set. |
64 | | |
65 | | \sa RollingPolicy::activateOptions() |
66 | | */ |
67 | | void activateOptions(helpers::Pool& p) override; |
68 | | |
69 | | /** |
70 | | A map from a name to the object implementing the (date or index) formatting. |
71 | | */ |
72 | | virtual pattern::PatternMap getFormatSpecifiers() const = 0; |
73 | | |
74 | | |
75 | | /** |
76 | | \copybrief spi::OptionHandler::setOption() |
77 | | |
78 | | Supported options | Supported values | Default value |
79 | | :-------------- | :----------------: | :---------------: |
80 | | FileNamePattern | (\ref legalChars "^") | - |
81 | | CreateIntermediateDirectories | True,False | False |
82 | | |
83 | | \anchor legalChars (^) Legal file name characters plus any conversion specifier supported by the concrete class. |
84 | | |
85 | | \sa getFormatSpecifiers() |
86 | | */ |
87 | | void setOption(const LogString& option, const LogString& value) override; |
88 | | |
89 | | /** |
90 | | * Set file name pattern. |
91 | | * @param fnp file name pattern. |
92 | | */ |
93 | | void setFileNamePattern(const LogString& fnp); |
94 | | |
95 | | /** |
96 | | * Get file name pattern. |
97 | | * @return file name pattern. |
98 | | */ |
99 | | LogString getFileNamePattern() const; |
100 | | |
101 | | bool getCreateIntermediateDirectories() const; |
102 | | void setCreateIntermediateDirectories(bool createIntermediate); |
103 | | |
104 | | PatternConverterList getPatternConverterList() const; |
105 | | |
106 | | protected: |
107 | | RollingPolicyBase(LOG4CXX_PRIVATE_PTR(RollingPolicyBasePrivate) priv); |
108 | | /** |
109 | | * Parse file name pattern. |
110 | | */ |
111 | | void parseFileNamePattern(); |
112 | | |
113 | | /** |
114 | | * Format file name. |
115 | | * |
116 | | * @param obj object to be evaluted in formatting, may not be null. |
117 | | * @param buf string buffer to which formatted file name is appended, may not be null. |
118 | | * @param p memory pool. |
119 | | */ |
120 | | void formatFileName(const helpers::ObjectPtr& obj, |
121 | | LogString& buf, helpers::Pool& p) const; |
122 | | |
123 | | LOG4CXX_NS::pattern::PatternConverterPtr getIntegerPatternConverter() const; |
124 | | LOG4CXX_NS::pattern::PatternConverterPtr getDatePatternConverter() const; |
125 | | }; |
126 | | |
127 | | LOG4CXX_PTR_DEF(RollingPolicyBase); |
128 | | |
129 | | } |
130 | | } |
131 | | |
132 | | #endif |