2 * @file time_and_size_based_rolling_policy.cpp
\r
3 * @brief log4cxx's rolling policy class. (time + size)
\r
5 * L7VSD: Linux Virtual Server for Layer7 Load Balancing
\r
6 * Copyright (C) 2008 NTT COMWARE Corporation.
\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
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
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
23 **********************************************************************/
\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
34 #include <boost/lexical_cast.hpp>
\r
35 #include "time_and_size_based_rolling_policy.h"
\r
37 #define DEFAULT_MAX_FILE_SIZE (10 * 1024 * 1024)
\r
39 using namespace log4cxx;
\r
40 using namespace log4cxx::rolling;
\r
41 using namespace log4cxx::helpers;
\r
42 using namespace log4cxx::pattern;
\r
44 IMPLEMENT_LOG4CXX_OBJECT(TimeAndSizeBasedRollingPolicy)
\r
47 * default constructor.
\r
48 * initialize member valiables
\r
52 TimeAndSizeBasedRollingPolicy::TimeAndSizeBasedRollingPolicy() :
\r
53 maxFileSize(DEFAULT_MAX_FILE_SIZE)
\r
58 * maxFileSize getter
\r
60 * @return maxFileSize
\r
62 size_t TimeAndSizeBasedRollingPolicy::getMaxFileSize()
\r
68 * maxFileSize setter
\r
69 * @param maxFileSize
\r
72 void TimeAndSizeBasedRollingPolicy::setMaxFileSize(size_t size)
\r
79 * @param option name
\r
83 void TimeAndSizeBasedRollingPolicy::setOption(const LogString& option, const LogString& value)
\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
91 StrictTimeBasedRollingPolicy::setOption(option, value);
\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
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
111 return (fileLength >= maxFileSize ||
\r
112 StrictTimeBasedRollingPolicy::isTriggeringEvent(appender, event, filename, fileLength));
\r