Path: blob/master/src/hotspot/share/logging/logDiagnosticCommand.cpp
40930 views
/*1* Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*22*/23#include "precompiled.hpp"24#include "logging/logConfiguration.hpp"25#include "logging/logDiagnosticCommand.hpp"26#include "memory/resourceArea.hpp"27#include "utilities/globalDefinitions.hpp"2829LogDiagnosticCommand::LogDiagnosticCommand(outputStream* output, bool heap_allocated)30: DCmdWithParser(output, heap_allocated),31_output("output", "The name or index (#<index>) of output to configure.", "STRING", false),32_output_options("output_options", "Options for the output.", "STRING", false),33_what("what", "Configures what tags to log.", "STRING", false),34_decorators("decorators", "Configures which decorators to use. Use 'none' or an empty value to remove all.", "STRING", false),35_disable("disable", "Turns off all logging and clears the log configuration.", "BOOLEAN", false),36_list("list", "Lists current log configuration.", "BOOLEAN", false),37_rotate("rotate", "Rotates all logs.", "BOOLEAN", false) {38_dcmdparser.add_dcmd_option(&_output);39_dcmdparser.add_dcmd_option(&_output_options);40_dcmdparser.add_dcmd_option(&_what);41_dcmdparser.add_dcmd_option(&_decorators);42_dcmdparser.add_dcmd_option(&_disable);43_dcmdparser.add_dcmd_option(&_list);44_dcmdparser.add_dcmd_option(&_rotate);45}4647int LogDiagnosticCommand::num_arguments() {48ResourceMark rm;49LogDiagnosticCommand* dcmd = new LogDiagnosticCommand(NULL, false);50if (dcmd != NULL) {51DCmdMark mark(dcmd);52return dcmd->_dcmdparser.num_arguments();53} else {54return 0;55}56}5758void LogDiagnosticCommand::registerCommand() {59uint32_t full_visibility = DCmd_Source_Internal | DCmd_Source_AttachAPI | DCmd_Source_MBean;60DCmdFactory::register_DCmdFactory(new DCmdFactoryImpl<LogDiagnosticCommand>(full_visibility, true, false));61}6263void LogDiagnosticCommand::execute(DCmdSource source, TRAPS) {64bool any_command = false;65if (_disable.has_value()) {66LogConfiguration::disable_logging();67any_command = true;68}6970if (_output.has_value() || _what.has_value() || _decorators.has_value()) {71if (!LogConfiguration::parse_log_arguments(_output.value(),72_what.value(),73_decorators.value(),74_output_options.value(),75output())) {76return;77}78any_command = true;79}8081if (_list.has_value()) {82LogConfiguration::describe(output());83any_command = true;84}8586if (_rotate.has_value()) {87LogConfiguration::rotate_all_outputs();88any_command = true;89}9091if (!any_command) {92// If no argument was provided, print usage93print_help(LogDiagnosticCommand::name());94}9596}979899