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