OSDN Git Service

trunk整理
[ultramonkey-l7/ultramonkey-l7-v3.git] / l7vsd / include / strict_time_based_rolling_policy.h
1 /*!
2  * @file  strict_time_based_rolling_policy.h
3  * @brief log4cxx's rolling policy class. (time)
4  *
5  * L7VSD: Linux Virtual Server for Layer7 Load Balancing
6  * Copyright (C) 2009  NTT COMWARE Corporation.
7  *
8  * This program is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU Lesser General Public
10  * License as published by the Free Software Foundation; either
11  * version 2.1 of the License, or (at your option) any later version.
12  *
13  * This program is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
16  * Lesser General Public License for more details.
17  *
18  * You should have received a copy of the GNU Lesser General Public
19  * License along with this library; if not, write to the Free Software
20  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
21  * 02110-1301 USA
22  *
23  **********************************************************************/
24
25 #ifndef __STRICT_TIME_BASED_ROLLING_POLICY_H__
26 #define __STRICT_TIME_BASED_ROLLING_POLICY_H__
27
28 #include <log4cxx/portability.h>
29 #include <log4cxx/rolling/rollingpolicybase.h>
30 #include <log4cxx/rolling/triggeringpolicy.h>
31 #include <log4cxx/rolling/fixedwindowrollingpolicy.h>
32 #include "logger_rotation_enum.h"
33
34 namespace log4cxx
35 {
36 namespace rolling
37 {
38 /*!
39  *  log4cxx time based rolling policy class.
40  *  this policy class can specify rolling time more strictly
41  *  than normal TimeBasedRollingPolicy.
42  */
43 class LOG4CXX_EXPORT StrictTimeBasedRollingPolicy :
44         public FixedWindowRollingPolicy,
45         public TriggeringPolicy
46 {
47         DECLARE_LOG4CXX_OBJECT(StrictTimeBasedRollingPolicy)
48         BEGIN_LOG4CXX_CAST_MAP()
49         LOG4CXX_CAST_ENTRY(StrictTimeBasedRollingPolicy)
50         LOG4CXX_CAST_ENTRY_CHAIN(FixedWindowRollingPolicy)
51         LOG4CXX_CAST_ENTRY_CHAIN(TriggeringPolicy)
52         END_LOG4CXX_CAST_MAP()
53
54 protected:
55         //! time of next rollover
56         time_t nextCheck;
57         /*!
58          *  rotation timing
59          *  LOG_TIM_YEAR   = yearly
60          *  LOG_TIM_MONTH  = monthly
61          *  LOG_TIM_WEEK   = weekly
62          *  LOG_TIM_DATE   = daily
63          *  LOG_TIM_HOUR   = hourly
64          */
65         l7vs::LOG_ROTATION_TIMING_TAG rotationTiming;
66         /*!
67          *  rotation timing value
68          *
69          *  rotation timing     value
70          *  -------------------------------------------------
71          *  LOG_TIM_YEAR    "03051500"    (3/5 15:00)
72          *  LOG_TIM_MONTH    "051100"    (5 11:00)
73          *  LOG_TIM_WEEK    "12000"        (mon 20:00) sun = 0, sat = 6
74          *  LOG_TIM_DATE    "1500"        (15:00)
75          *  LOG_TIM_HOUR    "45"        (45)
76          */
77         std::string rotationTimingValue;
78         //! calculate next rollover timing
79         time_t getNextCheck(time_t now_time);
80
81 public:
82         //! default constructor
83         StrictTimeBasedRollingPolicy();
84         //! increase reference count
85         void addRef() const;
86         //! decrease reference count
87         void releaseRef() const;
88         //! option setter
89         void setOption(const LogString &, const LogString &);
90         //! evaluate and activate options
91         void activateOptions(log4cxx::helpers::Pool &);
92
93         //! rotationTiming getter
94         l7vs::LOG_ROTATION_TIMING_TAG getRotationTiming();
95         //! rotationTiming setter
96         void setRotationTiming(const l7vs::LOG_ROTATION_TIMING_TAG);
97         //! rotationTimingValue getter
98         std::string getRotationTimingValue();
99         //! rotationTimingValue setter
100         void setRotationTimingValue(const std::string &);
101
102         //! rolling policy initialize
103         RolloverDescriptionPtr initialize(
104                 const LogString &file,
105                 const bool append,
106                 log4cxx::helpers::Pool &pool);
107         //! invoke when rollover event
108         RolloverDescriptionPtr rollover(const LogString &activeFile,
109                                         log4cxx::helpers::Pool &pool);
110
111         //! returns do rollover or not
112         virtual bool isTriggeringEvent(
113                 Appender *appender,
114                 const log4cxx::spi::LoggingEventPtr &event,
115                 const LogString &filename,
116                 size_t fileLength);
117
118 };
119 LOG4CXX_PTR_DEF(StrictTimeBasedRollingPolicy);
120 }
121 }
122
123 #endif    //__STRICT_TIME_BASED_ROLLING_POLICY_H__
124