Coverage Report

Created: 2026-01-10 07:03

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/logging-log4cxx/src/main/cpp/rollingpolicybase.cpp
Line
Count
Source
1
/*
2
 * Licensed to the Apache Software Foundation (ASF) under one or more
3
 * contributor license agreements.  See the NOTICE file distributed with
4
 * this work for additional information regarding copyright ownership.
5
 * The ASF licenses this file to You under the Apache License, Version 2.0
6
 * (the "License"); you may not use this file except in compliance with
7
 * the License.  You may obtain a copy of the License at
8
 *
9
 *      http://www.apache.org/licenses/LICENSE-2.0
10
 *
11
 * Unless required by applicable law or agreed to in writing, software
12
 * distributed under the License is distributed on an "AS IS" BASIS,
13
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
 * See the License for the specific language governing permissions and
15
 * limitations under the License.
16
 */
17
18
#include <log4cxx/logstring.h>
19
#include <log4cxx/rolling/rollingpolicybase.h>
20
#include <log4cxx/pattern/formattinginfo.h>
21
#include <log4cxx/helpers/stringhelper.h>
22
#include <log4cxx/helpers/loglog.h>
23
#include <log4cxx/helpers/exception.h>
24
#include <log4cxx/pattern/patternparser.h>
25
#include <log4cxx/pattern/integerpatternconverter.h>
26
#include <log4cxx/pattern/datepatternconverter.h>
27
#include <log4cxx/helpers/optionconverter.h>
28
#include <log4cxx/private/rollingpolicybase_priv.h>
29
30
using namespace LOG4CXX_NS;
31
using namespace LOG4CXX_NS::rolling;
32
using namespace LOG4CXX_NS::helpers;
33
using namespace LOG4CXX_NS::pattern;
34
35
IMPLEMENT_LOG4CXX_OBJECT(RollingPolicyBase)
36
37
RollingPolicyBase::RollingPolicyBase() :
38
373
  m_priv(std::make_unique<RollingPolicyBasePrivate>())
39
373
{
40
373
}
41
42
RollingPolicyBase::RollingPolicyBase( std::unique_ptr<RollingPolicyBasePrivate> priv ) :
43
0
  m_priv(std::move(priv)){
44
0
}
45
46
RollingPolicyBase::~RollingPolicyBase()
47
373
{
48
373
}
49
50
void RollingPolicyBase::activateOptions(LOG4CXX_NS::helpers::Pool& /* pool */)
51
0
{
52
0
  if (m_priv->fileNamePatternStr.length() > 0)
53
0
  {
54
0
    parseFileNamePattern();
55
0
  }
56
0
  else
57
0
  {
58
0
    LogString msg(LOG4CXX_STR("The FileNamePattern option must be set before using FixedWindowRollingPolicy."));
59
0
    LogString ref1(LOG4CXX_STR("See also http://logging.apache.org/log4j/codes.html#tbr_fnp_not_set"));
60
0
    LogLog::warn(msg);
61
0
    LogLog::warn(ref1);
62
0
    throw IllegalStateException();
63
0
  }
64
0
}
65
66
67
void RollingPolicyBase::setOption(const LogString& option, const LogString& value)
68
0
{
69
0
  if (StringHelper::equalsIgnoreCase(option,
70
0
      LOG4CXX_STR("FILENAMEPATTERN"),
71
0
      LOG4CXX_STR("filenamepattern")))
72
0
  {
73
0
    m_priv->fileNamePatternStr = value;
74
0
  }else if (StringHelper::equalsIgnoreCase(option,
75
0
      LOG4CXX_STR("CREATEINTERMEDIATEDIRECTORIES"),
76
0
      LOG4CXX_STR("createintermediatedirectories")))
77
0
  {
78
0
    m_priv->createIntermediateDirectories = OptionConverter::toBoolean(value, false);
79
0
  }
80
0
}
Unexecuted instantiation: log4cxx::rolling::RollingPolicyBase::setOption(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&)
Unexecuted instantiation: log4cxx::rolling::RollingPolicyBase::setOption(std::__1::basic_string<wchar_t, std::__1::char_traits<wchar_t>, std::__1::allocator<wchar_t> > const&, std::__1::basic_string<wchar_t, std::__1::char_traits<wchar_t>, std::__1::allocator<wchar_t> > const&)
81
82
void RollingPolicyBase::setFileNamePattern(const LogString& fnp)
83
373
{
84
373
  m_priv->fileNamePatternStr = fnp;
85
373
}
log4cxx::rolling::RollingPolicyBase::setFileNamePattern(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&)
Line
Count
Source
83
373
{
84
373
  m_priv->fileNamePatternStr = fnp;
85
373
}
Unexecuted instantiation: log4cxx::rolling::RollingPolicyBase::setFileNamePattern(std::__1::basic_string<wchar_t, std::__1::char_traits<wchar_t>, std::__1::allocator<wchar_t> > const&)
86
87
88
LogString RollingPolicyBase::getFileNamePattern() const
89
1.86k
{
90
1.86k
  return m_priv->fileNamePatternStr;
91
1.86k
}
92
93
/**
94
 *   Parse file name pattern.
95
 */
96
void RollingPolicyBase::parseFileNamePattern()
97
1.86k
{
98
1.86k
  m_priv->patternConverters.erase(m_priv->patternConverters.begin(), m_priv->patternConverters.end());
99
1.86k
  m_priv->patternFields.erase(m_priv->patternFields.begin(), m_priv->patternFields.end());
100
1.86k
  PatternParser::parse(m_priv->fileNamePatternStr,
101
1.86k
    m_priv->patternConverters,
102
1.86k
    m_priv->patternFields,
103
1.86k
    getFormatSpecifiers());
104
1.86k
}
105
106
/**
107
 * Format file name.
108
 *
109
 * @param obj object to be evaluted in formatting, may not be null.
110
 * @param buf string buffer to which formatted file name is appended, may not be null.
111
 */
112
void RollingPolicyBase::formatFileName(
113
  const ObjectPtr& obj,
114
  LogString& toAppendTo,
115
  Pool& pool) const
116
3.35k
{
117
3.35k
  std::vector<FormattingInfoPtr>::const_iterator formatterIter =
118
3.35k
    m_priv->patternFields.begin();
119
120
3.35k
  for (std::vector<PatternConverterPtr>::const_iterator
121
3.35k
    converterIter = m_priv->patternConverters.begin();
122
13.4k
    converterIter != m_priv->patternConverters.end();
123
10.0k
    converterIter++, formatterIter++)
124
10.0k
  {
125
10.0k
    auto startField = toAppendTo.length();
126
10.0k
    (*converterIter)->format(obj, toAppendTo, pool);
127
10.0k
    (*formatterIter)->format((int)startField, toAppendTo);
128
10.0k
  }
129
3.35k
}
log4cxx::rolling::RollingPolicyBase::formatFileName(std::__1::shared_ptr<log4cxx::helpers::Object> const&, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >&, log4cxx::helpers::Pool&) const
Line
Count
Source
116
3.35k
{
117
3.35k
  std::vector<FormattingInfoPtr>::const_iterator formatterIter =
118
3.35k
    m_priv->patternFields.begin();
119
120
3.35k
  for (std::vector<PatternConverterPtr>::const_iterator
121
3.35k
    converterIter = m_priv->patternConverters.begin();
122
13.4k
    converterIter != m_priv->patternConverters.end();
123
10.0k
    converterIter++, formatterIter++)
124
10.0k
  {
125
10.0k
    auto startField = toAppendTo.length();
126
10.0k
    (*converterIter)->format(obj, toAppendTo, pool);
127
10.0k
    (*formatterIter)->format((int)startField, toAppendTo);
128
10.0k
  }
129
3.35k
}
Unexecuted instantiation: log4cxx::rolling::RollingPolicyBase::formatFileName(std::__1::shared_ptr<log4cxx::helpers::Object> const&, std::__1::basic_string<wchar_t, std::__1::char_traits<wchar_t>, std::__1::allocator<wchar_t> >&, log4cxx::helpers::Pool&) const
130
131
132
PatternConverterPtr RollingPolicyBase::getIntegerPatternConverter() const
133
0
{
134
0
  for (std::vector<PatternConverterPtr>::const_iterator
135
0
    converterIter = m_priv->patternConverters.begin();
136
0
    converterIter != m_priv->patternConverters.end();
137
0
    converterIter++)
138
0
  {
139
0
    IntegerPatternConverterPtr intPattern;
140
0
    PatternConverterPtr patternptr = (*converterIter);
141
0
    intPattern = LOG4CXX_NS::cast<IntegerPatternConverter>(patternptr);
142
143
0
    if (intPattern != NULL)
144
0
    {
145
0
      return *converterIter;
146
0
    }
147
0
  }
148
149
0
  PatternConverterPtr noMatch;
150
0
  return noMatch;
151
0
}
Unexecuted instantiation: log4cxx::rolling::RollingPolicyBase::getIntegerPatternConverter() const
Unexecuted instantiation: log4cxx::rolling::RollingPolicyBase::getIntegerPatternConverter() const
152
153
PatternConverterPtr RollingPolicyBase::getDatePatternConverter() const
154
3.73k
{
155
3.73k
  for (std::vector<PatternConverterPtr>::const_iterator
156
3.73k
    converterIter = m_priv->patternConverters.begin();
157
7.46k
    converterIter != m_priv->patternConverters.end();
158
3.73k
    converterIter++)
159
7.46k
  {
160
7.46k
    DatePatternConverterPtr datePattern;
161
7.46k
    PatternConverterPtr patternptr = (*converterIter);
162
7.46k
    datePattern = LOG4CXX_NS::cast<DatePatternConverter>(patternptr);
163
164
7.46k
    if (datePattern != NULL)
165
3.73k
    {
166
3.73k
      return *converterIter;
167
3.73k
    }
168
7.46k
  }
169
170
0
  PatternConverterPtr noMatch;
171
0
  return noMatch;
172
3.73k
}
log4cxx::rolling::RollingPolicyBase::getDatePatternConverter() const
Line
Count
Source
154
1.86k
{
155
1.86k
  for (std::vector<PatternConverterPtr>::const_iterator
156
1.86k
    converterIter = m_priv->patternConverters.begin();
157
3.73k
    converterIter != m_priv->patternConverters.end();
158
1.86k
    converterIter++)
159
3.73k
  {
160
3.73k
    DatePatternConverterPtr datePattern;
161
3.73k
    PatternConverterPtr patternptr = (*converterIter);
162
3.73k
    datePattern = LOG4CXX_NS::cast<DatePatternConverter>(patternptr);
163
164
3.73k
    if (datePattern != NULL)
165
1.86k
    {
166
1.86k
      return *converterIter;
167
1.86k
    }
168
3.73k
  }
169
170
0
  PatternConverterPtr noMatch;
171
0
  return noMatch;
172
1.86k
}
log4cxx::rolling::RollingPolicyBase::getDatePatternConverter() const
Line
Count
Source
154
1.86k
{
155
1.86k
  for (std::vector<PatternConverterPtr>::const_iterator
156
1.86k
    converterIter = m_priv->patternConverters.begin();
157
3.73k
    converterIter != m_priv->patternConverters.end();
158
1.86k
    converterIter++)
159
3.73k
  {
160
3.73k
    DatePatternConverterPtr datePattern;
161
3.73k
    PatternConverterPtr patternptr = (*converterIter);
162
3.73k
    datePattern = LOG4CXX_NS::cast<DatePatternConverter>(patternptr);
163
164
3.73k
    if (datePattern != NULL)
165
1.86k
    {
166
1.86k
      return *converterIter;
167
1.86k
    }
168
3.73k
  }
169
170
0
  PatternConverterPtr noMatch;
171
0
  return noMatch;
172
1.86k
}
173
174
0
bool RollingPolicyBase::getCreateIntermediateDirectories() const{
175
0
  return m_priv->createIntermediateDirectories;
176
0
}
177
178
0
void RollingPolicyBase::setCreateIntermediateDirectories(bool createIntermediate){
179
0
  m_priv->createIntermediateDirectories = createIntermediate;
180
0
}
181
182
PatternConverterList RollingPolicyBase::getPatternConverterList() const
183
0
{
184
0
  return m_priv->patternConverters;
185
0
}