Coverage Report

Created: 2026-06-15 06:23

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/logging-log4cxx/src/main/cpp/propertysetter.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/config/propertysetter.h>
19
#include <log4cxx/helpers/loglog.h>
20
#include <log4cxx/helpers/optionconverter.h>
21
#include <log4cxx/spi/optionhandler.h>
22
#include <log4cxx/helpers/properties.h>
23
#include <log4cxx/appender.h>
24
25
26
using namespace LOG4CXX_NS;
27
using namespace LOG4CXX_NS::helpers;
28
using namespace LOG4CXX_NS::spi;
29
using namespace LOG4CXX_NS::config;
30
31
15.4k
PropertySetter::PropertySetter(const helpers::ObjectPtr& obj1) : obj(obj1)
32
15.4k
{
33
15.4k
}
34
35
void PropertySetter::setProperties(const helpers::ObjectPtr& obj, helpers::Properties& properties, const LogString& prefix)
36
4
{
37
4
  PropertySetter(obj).setProperties(properties, prefix);
38
4
}
log4cxx::config::PropertySetter::setProperties(std::__1::shared_ptr<log4cxx::helpers::Object> const&, log4cxx::helpers::Properties&, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&)
Line
Count
Source
36
2
{
37
2
  PropertySetter(obj).setProperties(properties, prefix);
38
2
}
log4cxx::config::PropertySetter::setProperties(std::__1::shared_ptr<log4cxx::helpers::Object> const&, log4cxx::helpers::Properties&, std::__1::basic_string<wchar_t, std::__1::char_traits<wchar_t>, std::__1::allocator<wchar_t> > const&)
Line
Count
Source
36
2
{
37
2
  PropertySetter(obj).setProperties(properties, prefix);
38
2
}
39
40
41
void PropertySetter::setProperties(helpers::Properties& properties, const LogString& prefix)
42
4
{
43
4
  size_t len = prefix.length();
44
45
4
  for (auto key : properties.propertyNames())
46
44
  {
47
    // handle only properties that start with the desired prefix.
48
44
    if (key.find(prefix) == 0)
49
6
    {
50
      // ignore key if it contains dots after the prefix
51
6
      if (key.find(0x2E /* '.' */, len + 1) != LogString::npos)
52
2
      {
53
2
        continue;
54
2
      }
55
56
4
      LogString value = OptionConverter::findAndSubst(key, properties);
57
4
      key = key.substr(len);
58
59
4
      if (key == LOG4CXX_STR("layout")
60
2
        && obj != 0
61
2
        && obj->instanceof(Appender::getStaticClass()))
62
2
      {
63
2
        continue;
64
2
      }
65
66
2
      setProperty(key, value);
67
2
    }
68
44
  }
69
70
4
  activate();
71
4
}
log4cxx::config::PropertySetter::setProperties(log4cxx::helpers::Properties&, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&)
Line
Count
Source
42
2
{
43
2
  size_t len = prefix.length();
44
45
2
  for (auto key : properties.propertyNames())
46
22
  {
47
    // handle only properties that start with the desired prefix.
48
22
    if (key.find(prefix) == 0)
49
3
    {
50
      // ignore key if it contains dots after the prefix
51
3
      if (key.find(0x2E /* '.' */, len + 1) != LogString::npos)
52
1
      {
53
1
        continue;
54
1
      }
55
56
2
      LogString value = OptionConverter::findAndSubst(key, properties);
57
2
      key = key.substr(len);
58
59
2
      if (key == LOG4CXX_STR("layout")
60
1
        && obj != 0
61
1
        && obj->instanceof(Appender::getStaticClass()))
62
1
      {
63
1
        continue;
64
1
      }
65
66
1
      setProperty(key, value);
67
1
    }
68
22
  }
69
70
2
  activate();
71
2
}
log4cxx::config::PropertySetter::setProperties(log4cxx::helpers::Properties&, std::__1::basic_string<wchar_t, std::__1::char_traits<wchar_t>, std::__1::allocator<wchar_t> > const&)
Line
Count
Source
42
2
{
43
2
  size_t len = prefix.length();
44
45
2
  for (auto key : properties.propertyNames())
46
22
  {
47
    // handle only properties that start with the desired prefix.
48
22
    if (key.find(prefix) == 0)
49
3
    {
50
      // ignore key if it contains dots after the prefix
51
3
      if (key.find(0x2E /* '.' */, len + 1) != LogString::npos)
52
1
      {
53
1
        continue;
54
1
      }
55
56
2
      LogString value = OptionConverter::findAndSubst(key, properties);
57
2
      key = key.substr(len);
58
59
2
      if (key == LOG4CXX_STR("layout")
60
1
        && obj != 0
61
1
        && obj->instanceof(Appender::getStaticClass()))
62
1
      {
63
1
        continue;
64
1
      }
65
66
1
      setProperty(key, value);
67
1
    }
68
22
  }
69
70
2
  activate();
71
2
}
72
73
void PropertySetter::setProperty(const LogString& option, const LogString& value)
74
2
{
75
2
  if (value.empty())
76
0
  {
77
0
    return;
78
0
  }
79
80
2
  if (obj != 0 && obj->instanceof(OptionHandler::getStaticClass()))
81
2
  {
82
2
    if (LogLog::isDebugEnabled())
83
0
    {
84
0
      LogLog::debug(LOG4CXX_STR("Setting option name=[") +
85
0
        option + LOG4CXX_STR("], value=[") + value + LOG4CXX_STR("]"));
86
0
    }
87
2
    OptionHandlerPtr handler = LOG4CXX_NS::cast<OptionHandler>(obj);
88
2
    handler->setOption(option, value);
89
2
  }
90
2
}
log4cxx::config::PropertySetter::setProperty(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&)
Line
Count
Source
74
1
{
75
1
  if (value.empty())
76
0
  {
77
0
    return;
78
0
  }
79
80
1
  if (obj != 0 && obj->instanceof(OptionHandler::getStaticClass()))
81
1
  {
82
1
    if (LogLog::isDebugEnabled())
83
0
    {
84
0
      LogLog::debug(LOG4CXX_STR("Setting option name=[") +
85
0
        option + LOG4CXX_STR("], value=[") + value + LOG4CXX_STR("]"));
86
0
    }
87
1
    OptionHandlerPtr handler = LOG4CXX_NS::cast<OptionHandler>(obj);
88
1
    handler->setOption(option, value);
89
1
  }
90
1
}
log4cxx::config::PropertySetter::setProperty(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&)
Line
Count
Source
74
1
{
75
1
  if (value.empty())
76
0
  {
77
0
    return;
78
0
  }
79
80
1
  if (obj != 0 && obj->instanceof(OptionHandler::getStaticClass()))
81
1
  {
82
1
    if (LogLog::isDebugEnabled())
83
0
    {
84
0
      LogLog::debug(LOG4CXX_STR("Setting option name=[") +
85
0
        option + LOG4CXX_STR("], value=[") + value + LOG4CXX_STR("]"));
86
0
    }
87
1
    OptionHandlerPtr handler = LOG4CXX_NS::cast<OptionHandler>(obj);
88
1
    handler->setOption(option, value);
89
1
  }
90
1
}
91
92
void PropertySetter::activate()
93
30.9k
{
94
30.9k
  if (obj != 0 && obj->instanceof(OptionHandler::getStaticClass()))
95
8
  {
96
8
    OptionHandlerPtr handler = LOG4CXX_NS::cast<OptionHandler>(obj);
97
8
    handler->activateOptions();
98
8
  }
99
30.9k
}
log4cxx::config::PropertySetter::activate()
Line
Count
Source
93
15.4k
{
94
15.4k
  if (obj != 0 && obj->instanceof(OptionHandler::getStaticClass()))
95
4
  {
96
4
    OptionHandlerPtr handler = LOG4CXX_NS::cast<OptionHandler>(obj);
97
4
    handler->activateOptions();
98
4
  }
99
15.4k
}
log4cxx::config::PropertySetter::activate()
Line
Count
Source
93
15.4k
{
94
15.4k
  if (obj != 0 && obj->instanceof(OptionHandler::getStaticClass()))
95
4
  {
96
4
    OptionHandlerPtr handler = LOG4CXX_NS::cast<OptionHandler>(obj);
97
4
    handler->activateOptions();
98
4
  }
99
15.4k
}
100
101
#if LOG4CXX_ABI_VERSION <= 15
102
void PropertySetter::setProperties(const helpers::ObjectPtr& obj,
103
  helpers::Properties& properties,
104
  const LogString& prefix,
105
  Pool&)
106
0
{
107
0
  PropertySetter(obj).setProperties(properties, prefix);
108
0
}
Unexecuted instantiation: log4cxx::config::PropertySetter::setProperties(std::__1::shared_ptr<log4cxx::helpers::Object> const&, log4cxx::helpers::Properties&, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, log4cxx::helpers::Pool&)
Unexecuted instantiation: log4cxx::config::PropertySetter::setProperties(std::__1::shared_ptr<log4cxx::helpers::Object> const&, log4cxx::helpers::Properties&, std::__1::basic_string<wchar_t, std::__1::char_traits<wchar_t>, std::__1::allocator<wchar_t> > const&, log4cxx::helpers::Pool&)
109
110
111
void PropertySetter::setProperties(helpers::Properties& properties,
112
  const LogString& prefix,
113
  Pool&)
114
0
{
115
0
  setProperties(properties, prefix);
116
0
}
Unexecuted instantiation: log4cxx::config::PropertySetter::setProperties(log4cxx::helpers::Properties&, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, log4cxx::helpers::Pool&)
Unexecuted instantiation: log4cxx::config::PropertySetter::setProperties(log4cxx::helpers::Properties&, std::__1::basic_string<wchar_t, std::__1::char_traits<wchar_t>, std::__1::allocator<wchar_t> > const&, log4cxx::helpers::Pool&)
117
118
void PropertySetter::setProperty(const LogString& option,
119
  const LogString& value,
120
  Pool&)
121
0
{
122
0
  setProperty(option, value);
123
0
}
Unexecuted instantiation: log4cxx::config::PropertySetter::setProperty(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&, log4cxx::helpers::Pool&)
Unexecuted instantiation: log4cxx::config::PropertySetter::setProperty(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&, log4cxx::helpers::Pool&)
124
125
void PropertySetter::activate(Pool& p)
126
0
{
127
0
  activate();
128
0
}
129
#endif