Coverage Report

Created: 2025-08-29 06:29

/src/logging-log4cxx/src/main/cpp/propertysetter.cpp
Line
Count
Source (jump to first uncovered line)
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/config/propertysetter.h>
20
#include <log4cxx/helpers/object.h>
21
#include <log4cxx/helpers/loglog.h>
22
#include <log4cxx/helpers/optionconverter.h>
23
#include <log4cxx/spi/optionhandler.h>
24
#include <log4cxx/helpers/properties.h>
25
#include <log4cxx/appender.h>
26
#include <log4cxx/layout.h>
27
#include <log4cxx/helpers/pool.h>
28
29
using namespace LOG4CXX_NS;
30
using namespace LOG4CXX_NS::helpers;
31
using namespace LOG4CXX_NS::spi;
32
using namespace LOG4CXX_NS::config;
33
34
2
PropertySetter::PropertySetter(const helpers::ObjectPtr& obj1) : obj(obj1)
35
2
{
36
2
}
37
38
void PropertySetter::setProperties(const helpers::ObjectPtr& obj,
39
  helpers::Properties& properties,
40
  const LogString& prefix,
41
  Pool& p)
42
2
{
43
2
  PropertySetter(obj).setProperties(properties, prefix, p);
44
2
}
45
46
47
void PropertySetter::setProperties(helpers::Properties& properties,
48
  const LogString& prefix,
49
  Pool& p)
50
2
{
51
2
  size_t len = prefix.length();
52
53
2
  for (auto key : properties.propertyNames())
54
8
  {
55
    // handle only properties that start with the desired frefix.
56
8
    if (key.find(prefix) == 0)
57
3
    {
58
      // ignore key if it contains dots after the prefix
59
3
      if (key.find(0x2E /* '.' */, len + 1) != LogString::npos)
60
1
      {
61
1
        continue;
62
1
      }
63
64
2
      LogString value = OptionConverter::findAndSubst(key, properties);
65
2
      key = key.substr(len);
66
67
2
      if (key == LOG4CXX_STR("layout")
68
2
        && obj != 0
69
2
        && obj->instanceof(Appender::getStaticClass()))
70
1
      {
71
1
        continue;
72
1
      }
73
74
1
      setProperty(key, value, p);
75
1
    }
76
8
  }
77
78
2
  activate(p);
79
2
}
80
81
void PropertySetter::setProperty(const LogString& option,
82
  const LogString& value,
83
  Pool&)
84
1
{
85
1
  if (value.empty())
86
0
  {
87
0
    return;
88
0
  }
89
90
1
  if (obj != 0 && obj->instanceof(OptionHandler::getStaticClass()))
91
1
  {
92
1
    if (LogLog::isDebugEnabled())
93
0
    {
94
0
      LogLog::debug(LOG4CXX_STR("Setting option name=[") +
95
0
        option + LOG4CXX_STR("], value=[") + value + LOG4CXX_STR("]"));
96
0
    }
97
1
    OptionHandlerPtr handler = LOG4CXX_NS::cast<OptionHandler>(obj);
98
1
    handler->setOption(option, value);
99
1
  }
100
1
}
101
102
void PropertySetter::activate(Pool& p)
103
2
{
104
2
  if (obj != 0 && obj->instanceof(OptionHandler::getStaticClass()))
105
2
  {
106
2
    OptionHandlerPtr handler = LOG4CXX_NS::cast<OptionHandler>(obj);
107
2
    handler->activateOptions(p);
108
2
  }
109
2
}