2 * @file time_and_size_based_rolling_policy.cpp
3 * @brief log4cxx's rolling policy class. (time + size)
5 * L7VSD: Linux Virtual Server for Layer7 Load Balancing
6 * Copyright (C) 2008 NTT COMWARE Corporation.
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.
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.
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
23 **********************************************************************/
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>
34 #include "time_and_size_based_rolling_policy.h"
35 #include "lexical_cast.h"
37 #define DEFAULT_MAX_FILE_SIZE (10 * 1024 * 1024)
39 using namespace log4cxx;
40 using namespace log4cxx::rolling;
41 using namespace log4cxx::helpers;
42 using namespace log4cxx::pattern;
44 IMPLEMENT_LOG4CXX_OBJECT(TimeAndSizeBasedRollingPolicy)
47 * default constructor.
48 * initialize member valiables
52 TimeAndSizeBasedRollingPolicy::TimeAndSizeBasedRollingPolicy() :
53 maxFileSize(DEFAULT_MAX_FILE_SIZE)
62 size_t TimeAndSizeBasedRollingPolicy::getMaxFileSize()
72 void TimeAndSizeBasedRollingPolicy::setMaxFileSize(size_t size)
83 void TimeAndSizeBasedRollingPolicy::setOption(const LogString& option, const LogString& value)
85 if (StringHelper::equalsIgnoreCase(option,
86 LOG4CXX_STR("MAXFILESIZE"),
87 LOG4CXX_STR("maxfilesize"))) {
88 maxFileSize = OptionConverter::toFileSize(value, DEFAULT_MAX_FILE_SIZE);
91 StrictTimeBasedRollingPolicy::setOption(option, value);
96 * returns do rollover or not
97 * @param appender (not use)
98 * @param event (not use)
99 * @param filename (not use)
101 * @retval true do rollover
102 * @retval false not rollover yet
104 bool TimeAndSizeBasedRollingPolicy::isTriggeringEvent(
106 const log4cxx::spi::LoggingEventPtr& event,
107 const LogString& filename,
111 return (fileLength >= maxFileSize ||
112 StrictTimeBasedRollingPolicy::isTriggeringEvent(appender, event, filename, fileLength));