/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 | 0 | PropertySetter::PropertySetter(const helpers::ObjectPtr& obj1) : obj(obj1) |
32 | 0 | { |
33 | 0 | } |
34 | | |
35 | | void PropertySetter::setProperties(const helpers::ObjectPtr& obj, helpers::Properties& properties, const LogString& prefix) |
36 | 0 | { |
37 | 0 | PropertySetter(obj).setProperties(properties, prefix); |
38 | 0 | } |
39 | | |
40 | | |
41 | | void PropertySetter::setProperties(helpers::Properties& properties, const LogString& prefix) |
42 | 0 | { |
43 | 0 | size_t len = prefix.length(); |
44 | |
|
45 | 0 | for (auto key : properties.propertyNames()) |
46 | 0 | { |
47 | | // handle only properties that start with the desired prefix. |
48 | 0 | if (key.find(prefix) == 0) |
49 | 0 | { |
50 | | // ignore key if it contains dots after the prefix |
51 | 0 | if (key.find(0x2E /* '.' */, len + 1) != LogString::npos) |
52 | 0 | { |
53 | 0 | continue; |
54 | 0 | } |
55 | | |
56 | 0 | LogString value = OptionConverter::findAndSubst(key, properties); |
57 | 0 | key = key.substr(len); |
58 | |
|
59 | 0 | if (key == LOG4CXX_STR("layout") |
60 | 0 | && obj != 0 |
61 | 0 | && obj->instanceof(Appender::getStaticClass())) |
62 | 0 | { |
63 | 0 | continue; |
64 | 0 | } |
65 | | |
66 | 0 | setProperty(key, value); |
67 | 0 | } |
68 | 0 | } |
69 | |
|
70 | 0 | activate(); |
71 | 0 | } |
72 | | |
73 | | void PropertySetter::setProperty(const LogString& option, const LogString& value) |
74 | 0 | { |
75 | 0 | if (value.empty()) |
76 | 0 | { |
77 | 0 | return; |
78 | 0 | } |
79 | | |
80 | 0 | if (obj != 0 && obj->instanceof(OptionHandler::getStaticClass())) |
81 | 0 | { |
82 | 0 | 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 | 0 | OptionHandlerPtr handler = LOG4CXX_NS::cast<OptionHandler>(obj); |
88 | 0 | handler->setOption(option, value); |
89 | 0 | } |
90 | 0 | } |
91 | | |
92 | | void PropertySetter::activate() |
93 | 0 | { |
94 | 0 | if (obj != 0 && obj->instanceof(OptionHandler::getStaticClass())) |
95 | 0 | { |
96 | 0 | OptionHandlerPtr handler = LOG4CXX_NS::cast<OptionHandler>(obj); |
97 | 0 | handler->activateOptions(); |
98 | 0 | } |
99 | 0 | } |
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 | } |
109 | | |
110 | | |
111 | | void PropertySetter::setProperties(helpers::Properties& properties, |
112 | | const LogString& prefix, |
113 | | Pool&) |
114 | 0 | { |
115 | 0 | setProperties(properties, prefix); |
116 | 0 | } |
117 | | |
118 | | void PropertySetter::setProperty(const LogString& option, |
119 | | const LogString& value, |
120 | | Pool&) |
121 | 0 | { |
122 | 0 | setProperty(option, value); |
123 | 0 | } |
124 | | |
125 | | void PropertySetter::activate(Pool& p) |
126 | 0 | { |
127 | 0 | activate(); |
128 | 0 | } |
129 | | #endif |