comparison src/hotspot/share/logging/logConfiguration.cpp @ 49188:e9ba8b40ca6f

8168722: Unified Logging configuration output needs simplifying Reviewed-by: rehn, lfoltan, hseigel
author mlarsson
date Wed, 28 Feb 2018 22:38:53 +0100
parents 268beecd832a
children
comparison
equal deleted inserted replaced
7:fe70e49dcfa9 8:fe9a930f1a49
218 assert(idx < _n_outputs, "Invalid index, idx = " SIZE_FORMAT " and _n_outputs = " SIZE_FORMAT, idx, _n_outputs); 218 assert(idx < _n_outputs, "Invalid index, idx = " SIZE_FORMAT " and _n_outputs = " SIZE_FORMAT, idx, _n_outputs);
219 LogOutput* output = _outputs[idx]; 219 LogOutput* output = _outputs[idx];
220 220
221 output->_reconfigured = true; 221 output->_reconfigured = true;
222 222
223 // Clear the previous config description 223 size_t on_level[LogLevel::Count] = {0};
224 output->clear_config_string();
225 224
226 bool enabled = false; 225 bool enabled = false;
227 for (LogTagSet* ts = LogTagSet::first(); ts != NULL; ts = ts->next()) { 226 for (LogTagSet* ts = LogTagSet::first(); ts != NULL; ts = ts->next()) {
228 LogLevelType level = selections.level_for(*ts); 227 LogLevelType level = selections.level_for(*ts);
229 228
230 // Ignore tagsets that do not, and will not log on the output 229 // Ignore tagsets that do not, and will not log on the output
231 if (!ts->has_output(output) && (level == LogLevel::NotMentioned || level == LogLevel::Off)) { 230 if (!ts->has_output(output) && (level == LogLevel::NotMentioned || level == LogLevel::Off)) {
231 on_level[LogLevel::Off]++;
232 continue; 232 continue;
233 } 233 }
234 234
235 // Update decorators before adding/updating output level, 235 // Update decorators before adding/updating output level,
236 // so that the tagset will have the necessary decorators when requiring them. 236 // so that the tagset will have the necessary decorators when requiring them.
239 } 239 }
240 240
241 // Set the new level, if it changed 241 // Set the new level, if it changed
242 if (level != LogLevel::NotMentioned) { 242 if (level != LogLevel::NotMentioned) {
243 ts->set_output_level(output, level); 243 ts->set_output_level(output, level);
244 } else {
245 // Look up the previously set level for this output on this tagset
246 level = ts->level_for(output);
244 } 247 }
245 248
246 if (level != LogLevel::Off) { 249 if (level != LogLevel::Off) {
247 // Keep track of whether or not the output is ever used by some tagset 250 // Keep track of whether or not the output is ever used by some tagset
248 enabled = true; 251 enabled = true;
249 252 }
250 if (level == LogLevel::NotMentioned) { 253
251 // Look up the previously set level for this output on this tagset 254 // Track of the number of tag sets on each level
252 level = ts->level_for(output); 255 on_level[level]++;
253 }
254
255 // Update the config description with this tagset and level
256 output->add_to_config_string(ts, level);
257 }
258 } 256 }
259 257
260 // It is now safe to set the new decorators for the actual output 258 // It is now safe to set the new decorators for the actual output
261 output->set_decorators(decorators); 259 output->set_decorators(decorators);
262 260
263 // Update the decorators on all tagsets to get rid of unused decorators 261 // Update the decorators on all tagsets to get rid of unused decorators
264 for (LogTagSet* ts = LogTagSet::first(); ts != NULL; ts = ts->next()) { 262 for (LogTagSet* ts = LogTagSet::first(); ts != NULL; ts = ts->next()) {
265 ts->update_decorators(); 263 ts->update_decorators();
266 } 264 }
267 265
268 if (enabled) { 266 if (!enabled && idx > 1) {
269 assert(strlen(output->config_string()) > 0, 267 // Output is unused and should be removed, unless it is stdout/stderr (idx < 2)
270 "Should always have a config description if the output is enabled.");
271 } else if (idx > 1) {
272 // Output is unused and should be removed.
273 delete_output(idx); 268 delete_output(idx);
274 } else { 269 return;
275 // Output is either stdout or stderr, which means we can't remove it. 270 }
276 // Update the config description to reflect that the output is disabled. 271
277 output->set_config_string("all=off"); 272 output->update_config_string(on_level);
278 } 273 assert(strlen(output->config_string()) > 0, "should always have a config description");
279 } 274 }
280 275
281 void LogConfiguration::disable_output(size_t idx) { 276 void LogConfiguration::disable_output(size_t idx) {
282 assert(idx < _n_outputs, "invalid index: " SIZE_FORMAT " (_n_outputs: " SIZE_FORMAT ")", idx, _n_outputs); 277 assert(idx < _n_outputs, "invalid index: " SIZE_FORMAT " (_n_outputs: " SIZE_FORMAT ")", idx, _n_outputs);
283 LogOutput* out = _outputs[idx]; 278 LogOutput* out = _outputs[idx];