OSDN Git Service

loggerをsslproxy版と統合。ログカテゴリの見直し。parameterでの呼出関数を廃止。parameterのイベント登録関数を追加
[ultramonkey-l7/ultramonkey-l7-v3.git] / logger / time_and_size_based_rolling_policy.cpp
1 /*\r
2  * @file  time_and_size_based_rolling_policy.cpp\r
3  * @brief log4cxx's rolling policy class. (time + size)\r
4  *\r
5  * L7VSD: Linux Virtual Server for Layer7 Load Balancing\r
6  * Copyright (C) 2008  NTT COMWARE Corporation.\r
7  *\r
8  * This program is free software; you can redistribute it and/or\r
9  * modify it under the terms of the GNU Lesser General Public\r
10  * License as published by the Free Software Foundation; either\r
11  * version 2.1 of the License, or (at your option) any later version.\r
12  *\r
13  * This program is distributed in the hope that it will be useful,\r
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of\r
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU\r
16  * Lesser General Public License for more details.\r
17  *      \r
18  * You should have received a copy of the GNU Lesser General Public\r
19  * License along with this library; if not, write to the Free Software\r
20  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA\r
21  * 02110-1301 USA\r
22  *\r
23  **********************************************************************/\r
24 \r
25 #include <log4cxx/logstring.h>\r
26 #include <log4cxx/pattern/filedatepatternconverter.h>\r
27 #include <log4cxx/helpers/date.h>\r
28 #include <log4cxx/rolling/filerenameaction.h>\r
29 #include <log4cxx/helpers/loglog.h>\r
30 #include <log4cxx/helpers/exception.h>\r
31 #include <log4cxx/helpers/stringhelper.h>\r
32 #include <log4cxx/helpers/optionconverter.h>\r
33 #include <time.h>\r
34 #include <boost/lexical_cast.hpp>\r
35 #include "time_and_size_based_rolling_policy.h"\r
36 \r
37 #define DEFAULT_MAX_FILE_SIZE (10 * 1024 * 1024)\r
38 \r
39 using namespace log4cxx;\r
40 using namespace log4cxx::rolling;\r
41 using namespace log4cxx::helpers;\r
42 using namespace log4cxx::pattern;\r
43 \r
44 IMPLEMENT_LOG4CXX_OBJECT(TimeAndSizeBasedRollingPolicy)\r
45 \r
46 /*!\r
47  * default constructor.\r
48  * initialize member valiables\r
49  * @param   void\r
50  * @return  void\r
51  */\r
52 TimeAndSizeBasedRollingPolicy::TimeAndSizeBasedRollingPolicy() :\r
53         maxFileSize(DEFAULT_MAX_FILE_SIZE)\r
54 {\r
55 }\r
56 \r
57 /*!\r
58  * maxFileSize getter\r
59  * @param   void\r
60  * @return  maxFileSize\r
61  */\r
62 size_t TimeAndSizeBasedRollingPolicy::getMaxFileSize()\r
63 {\r
64         return maxFileSize;\r
65 }\r
66 \r
67 /*!\r
68  * maxFileSize setter\r
69  * @param   maxFileSize\r
70  * @return  void\r
71  */ \r
72 void TimeAndSizeBasedRollingPolicy::setMaxFileSize(size_t size)\r
73 {\r
74         maxFileSize = size;\r
75 }\r
76 \r
77 /*!\r
78  * option setter\r
79  * @param   option name\r
80  * @param   value\r
81  * @return  void\r
82  */\r
83 void TimeAndSizeBasedRollingPolicy::setOption(const LogString& option, const LogString& value)\r
84 {\r
85         if (StringHelper::equalsIgnoreCase(option,\r
86                 LOG4CXX_STR("MAXFILESIZE"),\r
87                 LOG4CXX_STR("maxfilesize"))) {\r
88                 maxFileSize = OptionConverter::toFileSize(value, DEFAULT_MAX_FILE_SIZE);\r
89         }\r
90         else {\r
91                 StrictTimeBasedRollingPolicy::setOption(option, value);\r
92         }\r
93 }\r
94 \r
95 /*!\r
96  * returns do rollover or not\r
97  * @param   appender (not use)\r
98  * @param   event (not use)\r
99  * @param   filename (not use)\r
100  * @param   fileLength\r
101  * @retval  true do rollover\r
102  * @retval  false not rollover yet\r
103  */\r
104 bool TimeAndSizeBasedRollingPolicy::isTriggeringEvent(\r
105         Appender* appender,\r
106         const log4cxx::spi::LoggingEventPtr& event,\r
107         const LogString& filename,\r
108         size_t fileLength)  \r
109 {\r
110 \r
111         return (fileLength >= maxFileSize || \r
112                 StrictTimeBasedRollingPolicy::isTriggeringEvent(appender, event, filename, fileLength));\r
113 }\r