OSDN Git Service

Update INSTALL.ja.utf-8 for new release.
[ultramonkey-l7/ultramonkey-l7-v2.git] / logger / time_and_size_based_rolling_policy.cpp
1 /*
2  * @file  time_and_size_based_rolling_policy.cpp
3  * @brief log4cxx's rolling policy class. (time + size)
4  *
5  * L7VSD: Linux Virtual Server for Layer7 Load Balancing
6  * Copyright (C) 2008  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 #include <log4cxx/logstring.h>
26 #include <log4cxx/pattern/filedatepatternconverter.h>
27 #include <log4cxx/helpers/date.h>
28 #include <log4cxx/rolling/filerenameaction.h>
29 #include <log4cxx/helpers/loglog.h>
30 #include <log4cxx/helpers/exception.h>
31 #include <log4cxx/helpers/stringhelper.h>
32 #include <log4cxx/helpers/optionconverter.h>
33 #include <time.h>
34 #include "time_and_size_based_rolling_policy.h"
35 #include "lexical_cast.h"
36
37 #define DEFAULT_MAX_FILE_SIZE (10 * 1024 * 1024)
38
39 using namespace log4cxx;
40 using namespace log4cxx::rolling;
41 using namespace log4cxx::helpers;
42 using namespace log4cxx::pattern;
43
44 IMPLEMENT_LOG4CXX_OBJECT(TimeAndSizeBasedRollingPolicy)
45
46 /*!
47  * default constructor.
48  * initialize member valiables
49  * @param   void
50  * @return  void
51  */
52 TimeAndSizeBasedRollingPolicy::TimeAndSizeBasedRollingPolicy() :
53         maxFileSize(DEFAULT_MAX_FILE_SIZE)
54 {
55 }
56
57 /*!
58  * maxFileSize getter
59  * @param   void
60  * @return  maxFileSize
61  */
62 size_t TimeAndSizeBasedRollingPolicy::getMaxFileSize()
63 {
64         return maxFileSize;
65 }
66
67 /*!
68  * maxFileSize setter
69  * @param   maxFileSize
70  * @return  void
71  */ 
72 void TimeAndSizeBasedRollingPolicy::setMaxFileSize(size_t size)
73 {
74         maxFileSize = size;
75 }
76
77 /*!
78  * option setter
79  * @param   option name
80  * @param   value
81  * @return  void
82  */
83 void TimeAndSizeBasedRollingPolicy::setOption(const LogString& option, const LogString& value)
84 {
85         if (StringHelper::equalsIgnoreCase(option,
86                 LOG4CXX_STR("MAXFILESIZE"),
87                 LOG4CXX_STR("maxfilesize"))) {
88                 maxFileSize = OptionConverter::toFileSize(value, DEFAULT_MAX_FILE_SIZE);
89         }
90         else {
91                 StrictTimeBasedRollingPolicy::setOption(option, value);
92         }
93 }
94
95 /*!
96  * returns do rollover or not
97  * @param   appender (not use)
98  * @param   event (not use)
99  * @param   filename (not use)
100  * @param   fileLength
101  * @retval  true do rollover
102  * @retval  false not rollover yet
103  */
104 bool TimeAndSizeBasedRollingPolicy::isTriggeringEvent(
105         Appender* appender,
106         const log4cxx::spi::LoggingEventPtr& event,
107         const LogString& filename,
108         size_t fileLength)  
109 {
110
111         return (fileLength >= maxFileSize || 
112                 StrictTimeBasedRollingPolicy::isTriggeringEvent(appender, event, filename, fileLength));
113 }