logConfiguration.hpp revision 9655:37a97bb8b1ca
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#ifndef SHARE_VM_LOGGING_LOGCONFIGURATION_HPP
25#define SHARE_VM_LOGGING_LOGCONFIGURATION_HPP
26
27#include "logging/logLevel.hpp"
28#include "memory/allocation.hpp"
29#include "utilities/globalDefinitions.hpp"
30
31class LogOutput;
32class LogDecorators;
33class LogTagLevelExpression;
34
35// Global configuration of logging. Handles parsing and configuration of the logging framework,
36// and manages the list of configured log outputs. The actual tag and level configuration is
37// kept implicitly in the LogTagSets and their LogOutputLists. During configuration the tagsets
38// are iterated over and updated accordingly.
39class LogConfiguration : public AllStatic {
40 private:
41  static LogOutput**  _outputs;
42  static size_t       _n_outputs;
43  static bool         _post_initialized;
44
45  // Create a new output. Returns NULL if failed.
46  static LogOutput* new_output(char* name, const char* options = NULL);
47
48  // Add an output to the list of configured outputs. Returns the assigned index.
49  static size_t add_output(LogOutput* out);
50
51  // Delete a configured output. The stderr/stdout outputs can not be removed.
52  // Output should be completely disabled before it is deleted.
53  static void delete_output(size_t idx);
54
55  // Disable all logging to the specified output and then delete it (unless it is stdout/stderr).
56  static void disable_output(size_t idx);
57
58  // Get output index by name. Returns SIZE_MAX if output not found.
59  static size_t find_output(const char* name);
60
61  // Configure output (add or update existing configuration) to log on tag-level combination using specified decorators.
62  static void configure_output(size_t idx, const LogTagLevelExpression& tag_level_expression, const LogDecorators& decorators);
63
64 public:
65  // Initialization and finalization of log configuration, to be run at vm startup and shutdown respectively.
66  static void initialize(jlong vm_start_time);
67  static void finalize();
68
69  // Perform necessary post-initialization after VM startup. Enables reconfiguration of logging.
70  static void post_initialize();
71
72  // Disable all logging, equivalent to -Xlog:disable.
73  static void disable_logging();
74
75  // Configures logging on stdout for the given tags and level combination.
76  // Intended for mappings between -XX: flags and Unified Logging configuration.
77  // If exact_match is true, only tagsets with precisely the specified tags will be configured
78  // (exact_match=false is the same as "-Xlog:<tags>*=<level>", and exact_match=true is "-Xlog:<tags>=<level>").
79  // Tags should be specified using the LOG_TAGS macro, e.g.
80  // LogConfiguration::configure_stdout(LogLevel::<level>, <true/false>, LOG_TAGS(<tags>));
81  static void configure_stdout(LogLevelType level, bool exact_match, ...);
82
83  // Parse command line configuration. Parameter 'opts' is the string immediately following the -Xlog: argument ("gc" for -Xlog:gc).
84  static bool parse_command_line_arguments(const char* opts = "all");
85
86  // Parse separated configuration arguments (from JCmd/MBean and command line).
87  static bool parse_log_arguments(const char* outputstr,
88                                  const char* what,
89                                  const char* decoratorstr,
90                                  const char* output_options,
91                                  outputStream* errstream);
92
93  // Prints log configuration to outputStream, used by JCmd/MBean.
94  static void describe(outputStream* out);
95
96  // Prints usage help for command line log configuration.
97  static void print_command_line_help(FILE* out);
98
99  static bool is_post_initialized() {
100    return _post_initialized;
101  }
102
103  // Rotates all LogOutput
104  static void rotate_all_outputs();
105};
106
107#endif // SHARE_VM_LOGGING_LOGCONFIGURATION_HPP
108