1 martin 1.30 //%LICENSE////////////////////////////////////////////////////////////////
|
2 martin 1.31 //
|
3 martin 1.30 // Licensed to The Open Group (TOG) under one or more contributor license
4 // agreements. Refer to the OpenPegasusNOTICE.txt file distributed with
5 // this work for additional information regarding copyright ownership.
6 // Each contributor licenses this file to you under the OpenPegasus Open
7 // Source License; you may not use this file except in compliance with the
8 // License.
|
9 martin 1.31 //
|
10 martin 1.30 // Permission is hereby granted, free of charge, to any person obtaining a
11 // copy of this software and associated documentation files (the "Software"),
12 // to deal in the Software without restriction, including without limitation
13 // the rights to use, copy, modify, merge, publish, distribute, sublicense,
14 // and/or sell copies of the Software, and to permit persons to whom the
15 // Software is furnished to do so, subject to the following conditions:
|
16 martin 1.31 //
|
17 martin 1.30 // The above copyright notice and this permission notice shall be included
18 // in all copies or substantial portions of the Software.
|
19 martin 1.31 //
|
20 martin 1.30 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
|
21 martin 1.31 // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
22 martin 1.30 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
23 // IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
24 // CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
25 // TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
26 // SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
27 martin 1.31 //
|
28 martin 1.30 //////////////////////////////////////////////////////////////////////////
|
29 mike 1.2 //
30 //%/////////////////////////////////////////////////////////////////////////////
31
32
33 ///////////////////////////////////////////////////////////////////////////////
|
34 chip 1.15 //
|
35 mike 1.2 // This file has implementation for the log property owner class.
36 //
37 ///////////////////////////////////////////////////////////////////////////////
38
39 #include "LogPropertyOwner.h"
|
40 david 1.6 #include <Pegasus/Common/Logger.h>
|
41 mreddy 1.29 #include <Pegasus/Common/Constants.h>
42 #include <Pegasus/Common/StringConversion.h>
|
43 marek 1.38 #include "ConfigExceptions.h"
|
44 mike 1.2
45 PEGASUS_USING_STD;
46
47 PEGASUS_NAMESPACE_BEGIN
48
49 ///////////////////////////////////////////////////////////////////////////////
50 // LogPropertyOwner
51 ///////////////////////////////////////////////////////////////////////////////
52
53 static struct ConfigPropertyRow properties[] =
54 {
|
55 r.kieninger 1.24 #if defined(PEGASUS_OS_ZOS) && defined(PEGASUS_USE_RELEASE_DIRS)
|
56 ouyang.jian 1.27 # if !defined(PEGASUS_USE_SYSLOGS)
|
57 kumpf 1.33 {"logdir", "/var/wbem/logs", IS_DYNAMIC, IS_HIDDEN},
58 {"maxLogFileSizeKBytes", "32678", IS_DYNAMIC, IS_VISIBLE},
|
59 kumpf 1.32 # endif
|
60 kumpf 1.33 {"logLevel", "INFORMATION", IS_DYNAMIC, IS_VISIBLE}
|
61 ouyang.jian 1.27 #elif defined(PEGASUS_OS_PASE)
62 # if defined(PEGASUS_USE_RELEASE_CONFIG_OPTIONS)
|
63 kumpf 1.32 {"logdir", "/QOpenSys/QIBM/UserData/UME/Pegasus/logs", IS_DYNAMIC,
|
64 kumpf 1.33 IS_VISIBLE},
65 {"maxLogFileSizeKBytes", "32678", IS_DYNAMIC, IS_VISIBLE},
|
66 kumpf 1.32 # else
|
67 kumpf 1.33 {"logdir", "./logs", IS_DYNAMIC, IS_VISIBLE},
68 {"maxLogFileSizeKBytes", "32678", IS_DYNAMIC, IS_VISIBLE},
|
69 ouyang.jian 1.27 # endif
|
70 kumpf 1.33 {"logLevel", "INFORMATION", IS_DYNAMIC, IS_VISIBLE}
|
71 marek 1.22 #else
|
72 ouyang.jian 1.27 # if defined(PEGASUS_USE_RELEASE_CONFIG_OPTIONS)
73 # if !defined(PEGASUS_USE_SYSLOGS)
|
74 kumpf 1.33 {"logdir", "./logs", IS_DYNAMIC, IS_HIDDEN},
75 {"maxLogFileSizeKBytes", "32678", IS_DYNAMIC, IS_VISIBLE},
|
76 ouyang.jian 1.27 # endif
|
77 kumpf 1.33 {"logLevel", "SEVERE", IS_DYNAMIC, IS_HIDDEN}
|
78 ouyang.jian 1.27 # else
79 # if !defined(PEGASUS_USE_SYSLOGS)
|
80 kumpf 1.33 {"logdir", "./logs", IS_DYNAMIC, IS_VISIBLE},
81 {"maxLogFileSizeKBytes", "32678", IS_DYNAMIC, IS_VISIBLE},
|
82 ouyang.jian 1.27 # endif
|
83 kumpf 1.33 {"logLevel", "INFORMATION", IS_DYNAMIC, IS_VISIBLE}
|
84 ouyang.jian 1.27 # endif
|
85 marek 1.22 #endif
|
86 mike 1.2 };
87
88 const Uint32 NUM_PROPERTIES = sizeof(properties) / sizeof(properties[0]);
89
90
91 /** Constructors */
92 LogPropertyOwner::LogPropertyOwner()
93 {
|
94 konrad.r 1.17 #if !defined(PEGASUS_USE_SYSLOGS)
|
95 a.arora 1.12 _logdir.reset(new ConfigProperty);
|
96 mreddy 1.29 _maxLogFileSizeKBytes.reset(new ConfigProperty);
|
97 konrad.r 1.17 #endif
|
98 a.arora 1.12 _logLevel.reset(new ConfigProperty);
|
99 mike 1.2 }
100
101
102 /**
|
103 kumpf 1.25 Initialize the config properties.
|
104 mike 1.2 */
105 void LogPropertyOwner::initialize()
106 {
107 for (Uint32 i = 0; i < NUM_PROPERTIES; i++)
108 {
109 //
110 // Initialize the properties with default values
111 //
|
112 konrad.r 1.17 #if !defined (PEGASUS_USE_SYSLOGS)
|
113 kavita.gupta 1.34 if (String::equal(properties[i].propertyName, "logdir"))
|
114 mike 1.2 {
115 _logdir->propertyName = properties[i].propertyName;
116 _logdir->defaultValue = properties[i].defaultValue;
117 _logdir->currentValue = properties[i].defaultValue;
118 _logdir->plannedValue = properties[i].defaultValue;
119 _logdir->dynamic = properties[i].dynamic;
|
120 kumpf 1.9 _logdir->externallyVisible = properties[i].externallyVisible;
|
121 mike 1.2 }
|
122 kumpf 1.25 else
|
123 kavita.gupta 1.34 if (String::equal(
|
124 mreddy 1.29 properties[i].propertyName, "maxLogFileSizeKBytes"))
125 {
126 _maxLogFileSizeKBytes->propertyName = properties[i].propertyName;
127 _maxLogFileSizeKBytes->defaultValue = properties[i].defaultValue;
128 _maxLogFileSizeKBytes->currentValue = properties[i].defaultValue;
129 _maxLogFileSizeKBytes->plannedValue = properties[i].defaultValue;
130 _maxLogFileSizeKBytes->dynamic = properties[i].dynamic;
131 _maxLogFileSizeKBytes->externallyVisible =
132 properties[i].externallyVisible;
133
134 Uint64 logFileSize;
135 StringConversion::decimalStringToUint64(
136 _maxLogFileSizeKBytes->currentValue.getCString(),
137 logFileSize);
138
139 Logger::setMaxLogFileSize((Uint32)(logFileSize *1024));
140 }
141 else
|
142 konrad.r 1.17 #endif
|
143 kavita.gupta 1.34 if (String::equal(properties[i].propertyName, "logLevel"))
|
144 mike 1.2 {
|
145 david 1.6 _logLevel->propertyName = properties[i].propertyName;
146 _logLevel->defaultValue = properties[i].defaultValue;
147 _logLevel->currentValue = properties[i].defaultValue;
148 _logLevel->plannedValue = properties[i].defaultValue;
149 _logLevel->dynamic = properties[i].dynamic;
|
150 kumpf 1.9 _logLevel->externallyVisible = properties[i].externallyVisible;
|
151 david 1.7
|
152 kumpf 1.25 Logger::setlogLevelMask(_logLevel->currentValue);
|
153 mike 1.2 }
154 }
155 }
156
|
157 kumpf 1.4 struct ConfigProperty* LogPropertyOwner::_lookupConfigProperty(
|
158 aruran.ms 1.21 const String& name) const
|
159 mike 1.2 {
|
160 konrad.r 1.17 #if !defined(PEGASUS_USE_SYSLOGS)
|
161 kavita.gupta 1.34 if (String::equal(_logdir->propertyName, name))
|
162 mike 1.2 {
|
163 a.arora 1.12 return _logdir.get();
|
164 mike 1.2 }
|
165 kumpf 1.25 else
|
166 kavita.gupta 1.34 if (String::equal(_maxLogFileSizeKBytes->propertyName, name))
|
167 mreddy 1.29 {
168 return _maxLogFileSizeKBytes.get();
169 }
170 else
|
171 konrad.r 1.17 #endif
|
172 kavita.gupta 1.34 if (String::equal(_logLevel->propertyName, name))
|
173 mike 1.2 {
|
174 a.arora 1.12 return _logLevel.get();
|
175 mike 1.2 }
176 else
177 {
178 throw UnrecognizedConfigProperty(name);
179 }
180 }
181
|
182 chip 1.15 /**
|
183 kumpf 1.25 Get information about the specified property.
|
184 mike 1.2 */
|
185 kumpf 1.4 void LogPropertyOwner::getPropertyInfo(
|
186 chip 1.15 const String& name,
|
187 vijay.eli 1.20 Array<String>& propertyInfo) const
|
188 mike 1.2 {
|
189 aruran.ms 1.21 struct ConfigProperty* configProperty = _lookupConfigProperty(name);
|
190 kumpf 1.4
|
191 karl 1.37 buildPropertyInfo(name, configProperty, propertyInfo);
|
192 mike 1.2 }
193
|
194 chip 1.15 /**
|
195 kumpf 1.25 Get default value of the specified property.
|
196 kumpf 1.4 */
|
197 vijay.eli 1.20 String LogPropertyOwner::getDefaultValue(const String& name) const
|
198 kumpf 1.4 {
|
199 aruran.ms 1.21 struct ConfigProperty* configProperty = _lookupConfigProperty(name);
|
200 vijay.eli 1.20
|
201 kumpf 1.4 return configProperty->defaultValue;
202 }
203
|
204 chip 1.15 /**
|
205 kumpf 1.25 Get current value of the specified property.
|
206 mike 1.2 */
|
207 vijay.eli 1.20 String LogPropertyOwner::getCurrentValue(const String& name) const
|
208 mike 1.2 {
|
209 aruran.ms 1.21 struct ConfigProperty* configProperty = _lookupConfigProperty(name);
|
210 vijay.eli 1.20
|
211 kumpf 1.4 return configProperty->currentValue;
|
212 mike 1.2 }
213
|
214 chip 1.15 /**
|
215 kumpf 1.25 Get planned value of the specified property.
|
216 mike 1.2 */
|
217 vijay.eli 1.20 String LogPropertyOwner::getPlannedValue(const String& name) const
|
218 mike 1.2 {
|
219 aruran.ms 1.21 struct ConfigProperty* configProperty = _lookupConfigProperty(name);
|
220 vijay.eli 1.20
|
221 kumpf 1.4 return configProperty->plannedValue;
|
222 mike 1.2 }
223
224
|
225 chip 1.15 /**
|
226 kumpf 1.25 Init current value of the specified property to the specified value.
|
227 mike 1.2 */
228 void LogPropertyOwner::initCurrentValue(
|
229 chip 1.15 const String& name,
|
230 mike 1.2 const String& value)
231 {
|
232 kavita.gupta 1.34 if (String::equal(_logLevel->propertyName,name))
|
233 david 1.6 {
|
234 kumpf 1.25 _logLevel->currentValue = value;
235 Logger::setlogLevelMask(_logLevel->currentValue);
|
236 david 1.6 }
237 else
|
238 mreddy 1.29 #if !defined(PEGASUS_USE_SYSLOGS)
|
239 kavita.gupta 1.34 if (String::equal(_maxLogFileSizeKBytes->propertyName,name))
|
240 mreddy 1.29 {
241 Boolean status = false;
242 Uint64 maxLogFileSizeKBytes=0;
243
244 status = StringConversion::decimalStringToUint64(
245 value.getCString(),
246 maxLogFileSizeKBytes);
247
|
248 kumpf 1.32 if (!status||(maxLogFileSizeKBytes <
|
249 mreddy 1.29 PEGASUS_MAXLOGFILESIZEKBYTES_CONFIG_PROPERTY_MINIMUM_VALUE))
250 {
251 throw InvalidPropertyValue(name, value);
252 }
253 _maxLogFileSizeKBytes->currentValue = value;
254
255 Logger::setMaxLogFileSize((Uint32)(maxLogFileSizeKBytes*1024));
256 }
257 else
258 #endif
|
259 david 1.6 {
|
260 kumpf 1.25 struct ConfigProperty* configProperty = _lookupConfigProperty(name);
261 configProperty->currentValue = value;
|
262 david 1.6 }
|
263 mike 1.2 }
264
265
|
266 chip 1.15 /**
|
267 kumpf 1.25 Init planned value of the specified property to the specified value.
|
268 mike 1.2 */
269 void LogPropertyOwner::initPlannedValue(
|
270 chip 1.15 const String& name,
|
271 mike 1.2 const String& value)
272 {
|
273 kumpf 1.4 struct ConfigProperty* configProperty = _lookupConfigProperty(name);
274 configProperty->plannedValue = value;
|
275 mike 1.2 }
276
|
277 chip 1.15 /**
|
278 kumpf 1.25 Update current value of the specified property to the specified value.
|
279 mike 1.2 */
280 void LogPropertyOwner::updateCurrentValue(
|
281 chip 1.15 const String& name,
|
282 venkat.puvvada 1.35 const String& value,
|
283 venkat.puvvada 1.36 const String& userName,
284 Uint32 timeoutSeconds)
|
285 mike 1.2 {
286 //
287 // make sure the property is dynamic before updating the value.
288 //
289 if (!isDynamic(name))
290 {
|
291 chip 1.15 throw NonDynamicConfigProperty(name);
|
292 mike 1.2 }
293
294 //
|
295 chip 1.15 // Since the validations done in initCurrrentValue are sufficient and
296 // no additional validations required for update, we will call
|
297 mike 1.2 // initCurrrentValue.
298 //
299 initCurrentValue(name, value);
300 }
301
302
|
303 chip 1.15 /**
|
304 kumpf 1.25 Update planned value of the specified property to the specified value.
|
305 mike 1.2 */
306 void LogPropertyOwner::updatePlannedValue(
|
307 chip 1.15 const String& name,
|
308 mike 1.2 const String& value)
309 {
310 //
|
311 chip 1.15 // Since the validations done in initPlannedValue are sufficient and
312 // no additional validations required for update, we will call
|
313 mike 1.2 // initPlannedValue.
314 //
315 initPlannedValue(name, value);
316 }
317
|
318 chip 1.15 /**
|
319 kumpf 1.25 Checks to see if the given value is valid or not.
|
320 mike 1.2 */
|
321 kumpf 1.25 Boolean LogPropertyOwner::isValid(
322 const String& name,
323 const String& value) const
|
324 mike 1.2 {
|
325 kavita.gupta 1.34 if (String::equal(_logLevel->propertyName, name))
|
326 david 1.6 {
|
327 chip 1.15 //
328 // Check if the logLevel is valid
329 //
330 if (!Logger::isValidlogLevel(value))
331 {
332 throw InvalidPropertyValue(name, value);
|
333 david 1.6 }
334 }
335
|
336 kumpf 1.25 return true;
|
337 mike 1.2 }
338
|
339 chip 1.15 /**
|
340 kumpf 1.25 Checks to see if the specified property is dynamic or not.
|
341 mike 1.2 */
|
342 vijay.eli 1.20 Boolean LogPropertyOwner::isDynamic(const String& name) const
|
343 mike 1.2 {
|
344 aruran.ms 1.21 struct ConfigProperty* configProperty = _lookupConfigProperty(name);
|
345 vijay.eli 1.20
|
346 konrad.r 1.14 return (configProperty->dynamic == IS_DYNAMIC);
|
347 mike 1.2 }
348
349 PEGASUS_NAMESPACE_END
|