Apache log4cxx  Version 0.11.0
timebasedrollingpolicy.h
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>
23 #include <log4cxx/rolling/rollingpolicybase.h>
24 #include <log4cxx/rolling/triggeringpolicy.h>
25 #include <log4cxx/writerappender.h>
26 #include <log4cxx/helpers/outputstream.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 {
149  DECLARE_LOG4CXX_OBJECT(TimeBasedRollingPolicy)
150  BEGIN_LOG4CXX_CAST_MAP()
151  LOG4CXX_CAST_ENTRY(TimeBasedRollingPolicy)
152  LOG4CXX_CAST_ENTRY_CHAIN(RollingPolicyBase)
153  LOG4CXX_CAST_ENTRY_CHAIN(TriggeringPolicy)
154  END_LOG4CXX_CAST_MAP()
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 addRef() const;
220  void releaseRef() const;
221  void activateOptions(log4cxx::helpers::Pool& );
222 
223 #ifdef LOG4CXX_MULTI_PROCESS
224  virtual ~TimeBasedRollingPolicy();
225 
229  int createMMapFile(const std::string& lastfilename, log4cxx::helpers::Pool& pool);
230 
234  bool isMapFileEmpty(log4cxx::helpers::Pool& pool);
235 
239  void initMMapFile(const LogString& lastFileName, log4cxx::helpers::Pool& pool);
240 
244  int lockMMapFile(int type);
245 
249  int unLockMMapFile();
250 
254  const std::string createFile(const std::string& filename, const std::string& suffix, log4cxx::helpers::Pool& pool);
255 #endif
256 
260  RolloverDescriptionPtr initialize(
261  const LogString& currentActiveFile,
262  const bool append,
263  log4cxx::helpers::Pool& pool);
264 
268  RolloverDescriptionPtr rollover(
269  const LogString& currentActiveFile,
270  const bool append,
271  log4cxx::helpers::Pool& pool);
272 
284  virtual bool isTriggeringEvent(
285  Appender* appender,
286  const log4cxx::spi::LoggingEventPtr& event,
287  const LogString& filename,
288  size_t fileLength);
289 
290  protected:
291  log4cxx::pattern::PatternMap getFormatSpecifiers() const;
292 
293 };
294 
295 LOG4CXX_PTR_DEF(TimeBasedRollingPolicy);
296 
297 }
298 }
299 
300 #if defined(_MSC_VER)
301  #pragma warning ( pop )
302 #endif
303 
304 #endif
305 
A TriggeringPolicy controls the conditions under which rollover occurs.
Definition: triggeringpolicy.h:44
Implement this interface for your own strategies for outputting log statements.
Definition: appender.h:56
Definition: pool.h:32
TimeBasedRollingPolicy is both easy to configure and quite powerful.
Definition: timebasedrollingpolicy.h:146
Definition: appender.h:33
Implements methods common to most, it not all, rolling policies.
Definition: rollingpolicybase.h:49