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>
25 #include <log4cxx/writerappender.h>
27 #include <apr_mmap.h>
28 
29 #if defined(_MSC_VER)
30  #pragma warning ( push )
31  #pragma warning ( disable: 4251 )
32 #endif
33 
34 namespace log4cxx
35 {
36 
37 namespace rolling
38 {
39 
40 
41 
146 class 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:
219  void activateOptions(log4cxx::helpers::Pool& );
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,
261  log4cxx::helpers::Pool& pool);
262 
266  RolloverDescriptionPtr rollover(
267  const LogString& currentActiveFile,
268  const bool append,
269  log4cxx::helpers::Pool& pool);
270 
282  virtual bool isTriggeringEvent(
283  Appender* appender,
284  const log4cxx::spi::LoggingEventPtr& event,
285  const LogString& filename,
286  size_t fileLength);
287 
288  protected:
289  log4cxx::pattern::PatternMap getFormatSpecifiers() const;
290 
291 };
292 
294 
295 }
296 }
297 
298 #if defined(_MSC_VER)
299  #pragma warning ( pop )
300 #endif
301 
302 #endif
303 
#define LOG4CXX_CAST_ENTRY(Interface)
Definition: object.h:153
#define END_LOG4CXX_CAST_MAP()
Definition: object.h:147
A TriggeringPolicy controls the conditions under which rollover occurs.
Definition: triggeringpolicy.h:44
std::shared_ptr< LoggingEvent > LoggingEventPtr
Definition: appender.h:37
#define BEGIN_LOG4CXX_CAST_MAP()
Definition: object.h:141
LOG4CXX_PTR_DEF(Action)
#define DECLARE_LOG4CXX_OBJECT(object)
Definition: object.h:39
Implement this interface for your own strategies for outputting log statements.
Definition: appender.h:55
Definition: pool.h:32
#define LOG4CXX_CAST_ENTRY_CHAIN(Interface)
Definition: object.h:159
TimeBasedRollingPolicy is both easy to configure and quite powerful.
Definition: timebasedrollingpolicy.h:146
std::map< LogString, PatternConstructor > PatternMap
Definition: patternparser.h:41
Definition: appender.h:32
std::basic_string< logchar > LogString
Definition: logstring.h:66
Implements methods common to most, it not all, rolling policies.
Definition: rollingpolicybase.h:49