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 "runtime/mutexLocker.hpp"
29 #include "utilities/globalDefinitions.hpp"
30
31 LogDiagnosticCommand::LogDiagnosticCommand(outputStream* output, bool heap_allocated)
32 : DCmdWithParser(output, heap_allocated),
33 _output("output", "The name or index (#<index>) of output to configure.", "STRING", false),
34 _output_options("output_options", "Options for the output.", "STRING", false),
35 _what("what", "Configures what tags to log.", "STRING", false),
36 _decorators("decorators", "Configures which decorators to use. Use 'none' or an empty value to remove all.", "STRING", false),
37 _disable("disable", "Turns off all logging and clears the log configuration.", "BOOLEAN", false),
38 _list("list", "Lists current log configuration.", "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 }
46
47 int LogDiagnosticCommand::num_arguments() {
48 ResourceMark rm;
49 LogDiagnosticCommand* dcmd = new LogDiagnosticCommand(NULL, false);
50 if (dcmd != NULL) {
51 DCmdMark mark(dcmd);
52 return dcmd->_dcmdparser.num_arguments();
53 } else {
54 return 0;
55 }
56 }
57
58 void LogDiagnosticCommand::registerCommand() {
59 uint32_t full_visibility = DCmd_Source_Internal | DCmd_Source_AttachAPI | DCmd_Source_MBean;
60 DCmdFactory::register_DCmdFactory(new DCmdFactoryImpl<LogDiagnosticCommand>(full_visibility, true, false));
61 }
62
63 void LogDiagnosticCommand::execute(DCmdSource source, TRAPS) {
64 bool any_command = false;
66 MutexLocker ml(LogConfiguration_lock);
67 LogConfiguration::disable_logging();
68 any_command = true;
69 }
70
71 if (_output.has_value() || _what.has_value() || _decorators.has_value()) {
72 MutexLocker ml(LogConfiguration_lock);
73 if (!LogConfiguration::parse_log_arguments(_output.value(),
74 _what.value(),
75 _decorators.value(),
76 _output_options.value(),
77 output())) {
78 return;
79 }
80 any_command = true;
81 }
82
83 if (_list.has_value()) {
84 MutexLocker ml(LogConfiguration_lock);
85 LogConfiguration::describe(output());
86 any_command = true;
87 }
88
89 if (!any_command) {
90 // If no argument was provided, print usage
91 print_help(LogDiagnosticCommand::name());
92 }
93
94 }
|
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 "runtime/mutexLocker.hpp"
29 #include "utilities/globalDefinitions.hpp"
30
31 LogDiagnosticCommand::LogDiagnosticCommand(outputStream* output, bool heap_allocated)
32 : DCmdWithParser(output, heap_allocated),
33 _output("output", "The name or index (#<index>) of output to configure.", "STRING", false),
34 _output_options("output_options", "Options for the output.", "STRING", false),
35 _what("what", "Configures what tags to log.", "STRING", false),
36 _decorators("decorators", "Configures which decorators to use. Use 'none' or an empty value to remove all.", "STRING", false),
37 _disable("disable", "Turns off all logging and clears the log configuration.", "BOOLEAN", false),
38 _list("list", "Lists current log configuration.", "BOOLEAN", false),
39 _rotate("rotate", "Rotates current log.", "BOOLEAN", false) {
40 _dcmdparser.add_dcmd_option(&_output);
41 _dcmdparser.add_dcmd_option(&_output_options);
42 _dcmdparser.add_dcmd_option(&_what);
43 _dcmdparser.add_dcmd_option(&_decorators);
44 _dcmdparser.add_dcmd_option(&_disable);
45 _dcmdparser.add_dcmd_option(&_list);
46 _dcmdparser.add_dcmd_option(&_rotate);
47 }
48
49 int LogDiagnosticCommand::num_arguments() {
50 ResourceMark rm;
51 LogDiagnosticCommand* dcmd = new LogDiagnosticCommand(NULL, false);
52 if (dcmd != NULL) {
53 DCmdMark mark(dcmd);
54 return dcmd->_dcmdparser.num_arguments();
55 } else {
56 return 0;
57 }
58 }
59
60 void LogDiagnosticCommand::registerCommand() {
61 uint32_t full_visibility = DCmd_Source_Internal | DCmd_Source_AttachAPI | DCmd_Source_MBean;
62 DCmdFactory::register_DCmdFactory(new DCmdFactoryImpl<LogDiagnosticCommand>(full_visibility, true, false));
63 }
64
65 void LogDiagnosticCommand::execute(DCmdSource source, TRAPS) {
66 bool any_command = false;
68 MutexLocker ml(LogConfiguration_lock);
69 LogConfiguration::disable_logging();
70 any_command = true;
71 }
72
73 if (_output.has_value() || _what.has_value() || _decorators.has_value()) {
74 MutexLocker ml(LogConfiguration_lock);
75 if (!LogConfiguration::parse_log_arguments(_output.value(),
76 _what.value(),
77 _decorators.value(),
78 _output_options.value(),
79 output())) {
80 return;
81 }
82 any_command = true;
83 }
84
85 if (_list.has_value()) {
86 MutexLocker ml(LogConfiguration_lock);
87 LogConfiguration::describe(output());
88 any_command = true;
89 }
90
91 if (_rotate.has_value()) {
92 LogConfiguration::rotate_all_logfile();
93 any_command = true;
94 }
95
96 if (!any_command) {
97 // If no argument was provided, print usage
98 print_help(LogDiagnosticCommand::name());
99 }
100
101 }
|