logConfiguration.hpp revision 10940:8005261869c9
1265689Smav/* 2265689Smav * Copyright (c) 2015, 2016, Oracle and/or its affiliates. All rights reserved. 3265689Smav * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4265689Smav * 5265689Smav * This code is free software; you can redistribute it and/or modify it 6265689Smav * under the terms of the GNU General Public License version 2 only, as 7265689Smav * published by the Free Software Foundation. 8265689Smav * 9265689Smav * This code is distributed in the hope that it will be useful, but WITHOUT 10265689Smav * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 11265689Smav * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 12265689Smav * version 2 for more details (a copy is included in the LICENSE file that 13265689Smav * accompanied this code). 14265689Smav * 15265689Smav * You should have received a copy of the GNU General Public License version 16265689Smav * 2 along with this work; if not, write to the Free Software Foundation, 17265689Smav * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 18265689Smav * 19265689Smav * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 20265689Smav * or visit www.oracle.com if you need additional information or have any 21265689Smav * questions. 22265689Smav * 23265689Smav */ 24265689Smav#ifndef SHARE_VM_LOGGING_LOGCONFIGURATION_HPP 25265689Smav#define SHARE_VM_LOGGING_LOGCONFIGURATION_HPP 26265689Smav 27265689Smav#include "logging/logLevel.hpp" 28265689Smav#include "memory/allocation.hpp" 29265689Smav#include "utilities/globalDefinitions.hpp" 30265689Smav 31265689Smavclass LogOutput; 32265689Smavclass LogDecorators; 33265689Smavclass LogTagLevelExpression; 34265689Smav 35265689Smav// Global configuration of logging. Handles parsing and configuration of the logging framework, 36265689Smav// and manages the list of configured log outputs. The actual tag and level configuration is 37265689Smav// kept implicitly in the LogTagSets and their LogOutputLists. During configuration the tagsets 38265689Smav// are iterated over and updated accordingly. 39265689Smavclass LogConfiguration : public AllStatic { 40265689Smav friend class VMError; 41265689Smav public: 42265689Smav // Function for listeners 43265689Smav typedef void (*UpdateListenerFunction)(void); 44265689Smav 45265689Smav // Register callback for config change. 46265689Smav // The callback is always called with ConfigurationLock held, 47265689Smav // hence doing log reconfiguration from the callback will deadlock. 48265689Smav // The main Java thread may call this callback if there is an early registration 49265689Smav // else the attach listener JavaThread, started via diagnostic command, will be executing thread. 50265689Smav // The main purpose of this callback is to see if a loglevel have been changed. 51265689Smav // There is no way to unregister. 52265689Smav static void register_update_listener(UpdateListenerFunction cb); 53265689Smav 54265689Smav private: 55265689Smav static LogOutput** _outputs; 56265689Smav static size_t _n_outputs; 57265689Smav 58265689Smav static UpdateListenerFunction* _listener_callbacks; 59265689Smav static size_t _n_listener_callbacks; 60265689Smav 61265689Smav // Create a new output. Returns NULL if failed. 62265689Smav static LogOutput* new_output(char* name, const char* options, outputStream* errstream); 63265689Smav 64265689Smav // Add an output to the list of configured outputs. Returns the assigned index. 65265689Smav static size_t add_output(LogOutput* out); 66265689Smav 67265689Smav // Delete a configured output. The stderr/stdout outputs can not be removed. 68265689Smav // Output should be completely disabled before it is deleted. 69265689Smav static void delete_output(size_t idx); 70265689Smav 71265689Smav // Disable all logging to the specified output and then delete it (unless it is stdout/stderr). 72265689Smav static void disable_output(size_t idx); 73265689Smav 74265689Smav // Get output index by name. Returns SIZE_MAX if output not found. 75265689Smav static size_t find_output(const char* name); 76265689Smav 77265689Smav // Configure output (add or update existing configuration) to log on tag-level combination using specified decorators. 78265689Smav static void configure_output(size_t idx, const LogTagLevelExpression& tag_level_expression, const LogDecorators& decorators); 79265689Smav 80265689Smav // This should be called after any configuration change while still holding ConfigurationLock 81265689Smav static void notify_update_listeners(); 82265689Smav 83265689Smav // Respectively describe the built-in and runtime dependent portions of the configuration. 84265689Smav static void describe_available(outputStream* out); 85265689Smav static void describe_current_configuration(outputStream* out); 86265689Smav 87265689Smav 88265689Smav public: 89265689Smav // Initialization and finalization of log configuration, to be run at vm startup and shutdown respectively. 90265689Smav static void initialize(jlong vm_start_time); 91265689Smav static void finalize(); 92265689Smav 93265689Smav // Perform necessary post-initialization after VM startup. Enables reconfiguration of logging. 94265689Smav static void post_initialize(); 95265689Smav 96265689Smav // Disable all logging, equivalent to -Xlog:disable. 97265689Smav static void disable_logging(); 98265689Smav 99265689Smav // Configures logging on stdout for the given tags and level combination. 100265689Smav // Intended for mappings between -XX: flags and Unified Logging configuration. 101265689Smav // If exact_match is true, only tagsets with precisely the specified tags will be configured 102265689Smav // (exact_match=false is the same as "-Xlog:<tags>*=<level>", and exact_match=true is "-Xlog:<tags>=<level>"). 103265689Smav // Tags should be specified using the LOG_TAGS macro, e.g. 104265689Smav // LogConfiguration::configure_stdout(LogLevel::<level>, <true/false>, LOG_TAGS(<tags>)); 105265689Smav static void configure_stdout(LogLevelType level, bool exact_match, ...); 106265689Smav 107265689Smav // Parse command line configuration. Parameter 'opts' is the string immediately following the -Xlog: argument ("gc" for -Xlog:gc). 108265689Smav static bool parse_command_line_arguments(const char* opts = "all"); 109265689Smav 110265689Smav // Parse separated configuration arguments (from JCmd/MBean and command line). 111265689Smav static bool parse_log_arguments(const char* outputstr, 112265689Smav const char* what, 113265689Smav const char* decoratorstr, 114265689Smav const char* output_options, 115265689Smav outputStream* errstream); 116265689Smav 117265689Smav // Prints log configuration to outputStream, used by JCmd/MBean. 118265689Smav static void describe(outputStream* out); 119265689Smav 120265689Smav // Prints usage help for command line log configuration. 121265689Smav static void print_command_line_help(FILE* out); 122265689Smav 123265689Smav // Rotates all LogOutput 124265689Smav static void rotate_all_outputs(); 125265689Smav}; 126265689Smav 127265689Smav#endif // SHARE_VM_LOGGING_LOGCONFIGURATION_HPP 128265689Smav