Path: blob/master/src/hotspot/share/logging/logConfiguration.hpp
40930 views
/*1* Copyright (c) 2015, 2019, 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#ifndef SHARE_LOGGING_LOGCONFIGURATION_HPP24#define SHARE_LOGGING_LOGCONFIGURATION_HPP2526#include "logging/logLevel.hpp"27#include "memory/allocation.hpp"28#include "utilities/globalDefinitions.hpp"2930class LogOutput;31class LogDecorators;32class LogSelectionList;3334// Global configuration of logging. Handles parsing and configuration of the logging framework,35// and manages the list of configured log outputs. The actual tag and level configuration is36// kept implicitly in the LogTagSets and their LogOutputLists. During configuration the tagsets37// are iterated over and updated accordingly.38class LogConfiguration : public AllStatic {39friend class VMError;40friend class LogTestFixture;41public:42// Function for listeners43typedef void (*UpdateListenerFunction)(void);4445// Register callback for config change.46// The callback is always called with ConfigurationLock held,47// hence doing log reconfiguration from the callback will deadlock.48// The main Java thread may call this callback if there is an early registration49// else the attach listener JavaThread, started via diagnostic command, will be executing thread.50// The main purpose of this callback is to see if a loglevel have been changed.51// There is no way to unregister.52static void register_update_listener(UpdateListenerFunction cb);5354private:55static LogOutput** _outputs;56static size_t _n_outputs;5758static UpdateListenerFunction* _listener_callbacks;59static size_t _n_listener_callbacks;60static bool _async_mode;6162// Create a new output. Returns NULL if failed.63static LogOutput* new_output(const char* name, const char* options, outputStream* errstream);6465// Add an output to the list of configured outputs. Returns the assigned index.66static size_t add_output(LogOutput* out);6768// Delete a configured output. The stderr/stdout outputs can not be removed.69// Output should be completely disabled before it is deleted.70static void delete_output(size_t idx);7172// Disable all logging to all outputs. All outputs except stdout/stderr will be deleted.73static void disable_outputs();7475// Get output index by name. Returns SIZE_MAX if output not found.76static size_t find_output(const char* name);7778// Configure output (add or update existing configuration) to log on tag-level combination using specified decorators.79static void configure_output(size_t idx, const LogSelectionList& tag_level_expression, const LogDecorators& decorators);8081// This should be called after any configuration change while still holding ConfigurationLock82static void notify_update_listeners();8384// Respectively describe the built-in and runtime dependent portions of the configuration.85static void describe_available(outputStream* out);86static void describe_current_configuration(outputStream* out);878889public:90// Initialization and finalization of log configuration, to be run at vm startup and shutdown respectively.91static void initialize(jlong vm_start_time);92static void finalize();9394// Perform necessary post-initialization after VM startup. Enables reconfiguration of logging.95static void post_initialize();9697// Disable all logging, equivalent to -Xlog:disable.98static void disable_logging();99100// Configures logging on stdout for the given tags and level combination.101// Intended for mappings between -XX: flags and Unified Logging configuration.102// If exact_match is true, only tagsets with precisely the specified tags will be configured103// (exact_match=false is the same as "-Xlog:<tags>*=<level>", and exact_match=true is "-Xlog:<tags>=<level>").104// Tags should be specified using the LOG_TAGS macro, e.g.105// LogConfiguration::configure_stdout(LogLevel::<level>, <true/false>, LOG_TAGS(<tags>));106static void configure_stdout(LogLevelType level, int exact_match, ...);107108// Parse command line configuration. Parameter 'opts' is the string immediately following the -Xlog: argument ("gc" for -Xlog:gc).109static bool parse_command_line_arguments(const char* opts = "all");110111// Parse separated configuration arguments (from JCmd/MBean and command line).112static bool parse_log_arguments(const char* outputstr,113const char* what,114const char* decoratorstr,115const char* output_options,116outputStream* errstream);117118// Prints log configuration to outputStream, used by JCmd/MBean.119static void describe(outputStream* out);120121// Prints usage help for command line log configuration.122static void print_command_line_help(outputStream* out);123124// Rotates all LogOutput125static void rotate_all_outputs();126127static bool is_async_mode() { return _async_mode; }128static void set_async_mode(bool value) {129_async_mode = value;130}131};132133#endif // SHARE_LOGGING_LOGCONFIGURATION_HPP134135136