Apache log4cxx Version 0.13.0
timebasedrollingpolicy.h
Go to the documentation of this file.
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
19#if !defined(_LOG4CXX_ROLLING_TIME_BASED_ROLLING_POLICY_H)
20#define _LOG4CXX_ROLLING_TIME_BASED_ROLLING_POLICY_H
21
22#include <log4cxx/portability.h>
27#include <apr_mmap.h>
28
29#if defined(_MSC_VER)
30 #pragma warning ( push )
31 #pragma warning ( disable: 4251 )
32#endif
33
34namespace log4cxx
35{
36
37namespace rolling
38{
39
40
41
146class LOG4CXX_EXPORT TimeBasedRollingPolicy : public RollingPolicyBase,
147 public TriggeringPolicy
148{
155
156 private:
160 log4cxx_time_t nextCheck;
161
165 LogString lastFileName;
166
170 apr_mmap_t* _mmap;
171
172 /*
173 * pool for mmap handler
174 * */
175 log4cxx::helpers::Pool* _mmapPool;
176
180 apr_file_t* _file_map;
181
185 std::string _mapFileName;
186
187 /*
188 * lock file handle
189 * */
190 apr_file_t* _lock_file;
191
200 bool bAlreadyInitialized;
201
202 /*
203 * If the current file name contains date information, retrieve the current writting file from mmap
204 * */
205 bool bRefreshCurFile;
206
207 /*
208 * mmap file name
209 * */
210 LogString _fileNamePattern;
211
215 int suffixLength;
216
217 public:
220
221#ifdef LOG4CXX_MULTI_PROCESS
222 virtual ~TimeBasedRollingPolicy();
223
227 int createMMapFile(const std::string& lastfilename, log4cxx::helpers::Pool& pool);
228
232 bool isMapFileEmpty(log4cxx::helpers::Pool& pool);
233
237 void initMMapFile(const LogString& lastFileName, log4cxx::helpers::Pool& pool);
238
242 int lockMMapFile(int type);
243
247 int unLockMMapFile();
248
252 const std::string createFile(const std::string& filename, const std::string& suffix, log4cxx::helpers::Pool& pool);
253#endif
254
258 RolloverDescriptionPtr initialize(
259 const LogString& currentActiveFile,
260 const bool append,
262
266 RolloverDescriptionPtr rollover(
267 const LogString& currentActiveFile,
268 const bool append,
270
282 virtual bool isTriggeringEvent(
283 Appender* appender,
285 const LogString& filename,
286 size_t fileLength);
287
288 protected:
290
291};
292
294
295}
296}
297
298#if defined(_MSC_VER)
299 #pragma warning ( pop )
300#endif
301
302#endif
303
Implement this interface for your own strategies for outputting log statements.
Definition: appender.h:57
Definition: pool.h:33
Implements methods common to most, it not all, rolling policies.
Definition: rollingpolicybase.h:52
TimeBasedRollingPolicy is both easy to configure and quite powerful.
Definition: timebasedrollingpolicy.h:148
log4cxx::pattern::PatternMap getFormatSpecifiers() const
virtual bool isTriggeringEvent(Appender *appender, const log4cxx::spi::LoggingEventPtr &event, const LogString &filename, size_t fileLength)
Determines if a rollover may be appropriate at this time.
RolloverDescriptionPtr initialize(const LogString &currentActiveFile, const bool append, log4cxx::helpers::Pool &pool)
Initialize the policy and return any initial actions for rolling file appender.Description of the ini...
RolloverDescriptionPtr rollover(const LogString &currentActiveFile, const bool append, log4cxx::helpers::Pool &pool)
Prepare for a rollover.This method is called prior to closing the active log file,...
void activateOptions(log4cxx::helpers::Pool &)
Activate the options that were previously set with calls to option setters.
A TriggeringPolicy controls the conditions under which rollover occurs.
Definition: triggeringpolicy.h:47
std::map< LogString, PatternConstructor > PatternMap
Definition: patternparser.h:41
LOG4CXX_PTR_DEF(Action)
std::shared_ptr< LoggingEvent > LoggingEventPtr
Definition: appender.h:38
Definition: messagehandler.h:23
std::basic_string< logchar > LogString
Definition: logstring.h:66
#define LOG4CXX_CAST_ENTRY(Interface)
Definition: object.h:153
#define END_LOG4CXX_CAST_MAP()
Definition: object.h:147
#define DECLARE_LOG4CXX_OBJECT(object)
Definition: object.h:39
#define LOG4CXX_CAST_ENTRY_CHAIN(Interface)
Definition: object.h:159
#define BEGIN_LOG4CXX_CAST_MAP()
Definition: object.h:141