author | rehn |
Tue, 15 Mar 2016 14:41:07 +0100 | |
changeset 37161 | e881f320966e |
parent 37108 | fe800ec86077 |
child 37994 | 1a816b464178 |
permissions | -rw-r--r-- |
33097 | 1 |
/* |
37108
fe800ec86077
8151264: Add a notification mechanism for UL configuration changes.
rehn
parents:
35230
diff
changeset
|
2 |
* Copyright (c) 2015, 2016, Oracle and/or its affiliates. All rights reserved. |
33097 | 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 |
||
34316
4d876653d940
8142952: Unified Logging framework does not allow multiple -Xlog: arguments.
mlarsson
parents:
33097
diff
changeset
|
27 |
#include "logging/logLevel.hpp" |
33097 | 28 |
#include "memory/allocation.hpp" |
29 |
#include "utilities/globalDefinitions.hpp" |
|
30 |
||
31 |
class LogOutput; |
|
32 |
class LogDecorators; |
|
33 |
class 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. |
|
39 |
class LogConfiguration : public AllStatic { |
|
37108
fe800ec86077
8151264: Add a notification mechanism for UL configuration changes.
rehn
parents:
35230
diff
changeset
|
40 |
public: |
fe800ec86077
8151264: Add a notification mechanism for UL configuration changes.
rehn
parents:
35230
diff
changeset
|
41 |
// Function for listeners |
fe800ec86077
8151264: Add a notification mechanism for UL configuration changes.
rehn
parents:
35230
diff
changeset
|
42 |
typedef void (*UpdateListenerFunction)(void); |
fe800ec86077
8151264: Add a notification mechanism for UL configuration changes.
rehn
parents:
35230
diff
changeset
|
43 |
|
fe800ec86077
8151264: Add a notification mechanism for UL configuration changes.
rehn
parents:
35230
diff
changeset
|
44 |
// Register callback for config change. |
fe800ec86077
8151264: Add a notification mechanism for UL configuration changes.
rehn
parents:
35230
diff
changeset
|
45 |
// The callback is always called with ConfigurationLock held, |
fe800ec86077
8151264: Add a notification mechanism for UL configuration changes.
rehn
parents:
35230
diff
changeset
|
46 |
// hence doing log reconfiguration from the callback will deadlock. |
fe800ec86077
8151264: Add a notification mechanism for UL configuration changes.
rehn
parents:
35230
diff
changeset
|
47 |
// The main Java thread may call this callback if there is an early registration |
fe800ec86077
8151264: Add a notification mechanism for UL configuration changes.
rehn
parents:
35230
diff
changeset
|
48 |
// else the attach listener JavaThread, started via diagnostic command, will be executing thread. |
fe800ec86077
8151264: Add a notification mechanism for UL configuration changes.
rehn
parents:
35230
diff
changeset
|
49 |
// The main purpose of this callback is to see if a loglevel have been changed. |
fe800ec86077
8151264: Add a notification mechanism for UL configuration changes.
rehn
parents:
35230
diff
changeset
|
50 |
// There is no way to unregister. |
fe800ec86077
8151264: Add a notification mechanism for UL configuration changes.
rehn
parents:
35230
diff
changeset
|
51 |
static void register_update_listener(UpdateListenerFunction cb); |
fe800ec86077
8151264: Add a notification mechanism for UL configuration changes.
rehn
parents:
35230
diff
changeset
|
52 |
|
33097 | 53 |
private: |
54 |
static LogOutput** _outputs; |
|
55 |
static size_t _n_outputs; |
|
56 |
||
37108
fe800ec86077
8151264: Add a notification mechanism for UL configuration changes.
rehn
parents:
35230
diff
changeset
|
57 |
static UpdateListenerFunction* _listener_callbacks; |
fe800ec86077
8151264: Add a notification mechanism for UL configuration changes.
rehn
parents:
35230
diff
changeset
|
58 |
static size_t _n_listener_callbacks; |
fe800ec86077
8151264: Add a notification mechanism for UL configuration changes.
rehn
parents:
35230
diff
changeset
|
59 |
|
33097 | 60 |
// Create a new output. Returns NULL if failed. |
35229
b8d78ee728b2
8144220: UL does not support full path names for log files on windows
mlarsson
parents:
34637
diff
changeset
|
61 |
static LogOutput* new_output(char* name, const char* options, outputStream* errstream); |
33097 | 62 |
|
63 |
// Add an output to the list of configured outputs. Returns the assigned index. |
|
64 |
static size_t add_output(LogOutput* out); |
|
65 |
||
66 |
// Delete a configured output. The stderr/stdout outputs can not be removed. |
|
67 |
// Output should be completely disabled before it is deleted. |
|
68 |
static void delete_output(size_t idx); |
|
69 |
||
70 |
// Disable all logging to the specified output and then delete it (unless it is stdout/stderr). |
|
71 |
static void disable_output(size_t idx); |
|
72 |
||
73 |
// Get output index by name. Returns SIZE_MAX if output not found. |
|
74 |
static size_t find_output(const char* name); |
|
75 |
||
76 |
// Configure output (add or update existing configuration) to log on tag-level combination using specified decorators. |
|
77 |
static void configure_output(size_t idx, const LogTagLevelExpression& tag_level_expression, const LogDecorators& decorators); |
|
78 |
||
37108
fe800ec86077
8151264: Add a notification mechanism for UL configuration changes.
rehn
parents:
35230
diff
changeset
|
79 |
// This should be called after any configuration change while still holding ConfigurationLock |
fe800ec86077
8151264: Add a notification mechanism for UL configuration changes.
rehn
parents:
35230
diff
changeset
|
80 |
static void notify_update_listeners(); |
fe800ec86077
8151264: Add a notification mechanism for UL configuration changes.
rehn
parents:
35230
diff
changeset
|
81 |
|
33097 | 82 |
public: |
83 |
// Initialization and finalization of log configuration, to be run at vm startup and shutdown respectively. |
|
84 |
static void initialize(jlong vm_start_time); |
|
85 |
static void finalize(); |
|
86 |
||
87 |
// Perform necessary post-initialization after VM startup. Enables reconfiguration of logging. |
|
88 |
static void post_initialize(); |
|
89 |
||
90 |
// Disable all logging, equivalent to -Xlog:disable. |
|
91 |
static void disable_logging(); |
|
92 |
||
34316
4d876653d940
8142952: Unified Logging framework does not allow multiple -Xlog: arguments.
mlarsson
parents:
33097
diff
changeset
|
93 |
// Configures logging on stdout for the given tags and level combination. |
4d876653d940
8142952: Unified Logging framework does not allow multiple -Xlog: arguments.
mlarsson
parents:
33097
diff
changeset
|
94 |
// Intended for mappings between -XX: flags and Unified Logging configuration. |
4d876653d940
8142952: Unified Logging framework does not allow multiple -Xlog: arguments.
mlarsson
parents:
33097
diff
changeset
|
95 |
// If exact_match is true, only tagsets with precisely the specified tags will be configured |
4d876653d940
8142952: Unified Logging framework does not allow multiple -Xlog: arguments.
mlarsson
parents:
33097
diff
changeset
|
96 |
// (exact_match=false is the same as "-Xlog:<tags>*=<level>", and exact_match=true is "-Xlog:<tags>=<level>"). |
4d876653d940
8142952: Unified Logging framework does not allow multiple -Xlog: arguments.
mlarsson
parents:
33097
diff
changeset
|
97 |
// Tags should be specified using the LOG_TAGS macro, e.g. |
4d876653d940
8142952: Unified Logging framework does not allow multiple -Xlog: arguments.
mlarsson
parents:
33097
diff
changeset
|
98 |
// LogConfiguration::configure_stdout(LogLevel::<level>, <true/false>, LOG_TAGS(<tags>)); |
4d876653d940
8142952: Unified Logging framework does not allow multiple -Xlog: arguments.
mlarsson
parents:
33097
diff
changeset
|
99 |
static void configure_stdout(LogLevelType level, bool exact_match, ...); |
4d876653d940
8142952: Unified Logging framework does not allow multiple -Xlog: arguments.
mlarsson
parents:
33097
diff
changeset
|
100 |
|
33097 | 101 |
// Parse command line configuration. Parameter 'opts' is the string immediately following the -Xlog: argument ("gc" for -Xlog:gc). |
102 |
static bool parse_command_line_arguments(const char* opts = "all"); |
|
103 |
||
104 |
// Parse separated configuration arguments (from JCmd/MBean and command line). |
|
105 |
static bool parse_log_arguments(const char* outputstr, |
|
106 |
const char* what, |
|
107 |
const char* decoratorstr, |
|
108 |
const char* output_options, |
|
109 |
outputStream* errstream); |
|
110 |
||
111 |
// Prints log configuration to outputStream, used by JCmd/MBean. |
|
112 |
static void describe(outputStream* out); |
|
113 |
||
114 |
// Prints usage help for command line log configuration. |
|
115 |
static void print_command_line_help(FILE* out); |
|
34637
9b9298044d23
8140556: Add force rotation option to VM.log jcmd
ysuenaga
parents:
34316
diff
changeset
|
116 |
|
9b9298044d23
8140556: Add force rotation option to VM.log jcmd
ysuenaga
parents:
34316
diff
changeset
|
117 |
// Rotates all LogOutput |
9b9298044d23
8140556: Add force rotation option to VM.log jcmd
ysuenaga
parents:
34316
diff
changeset
|
118 |
static void rotate_all_outputs(); |
33097 | 119 |
}; |
120 |
||
121 |
#endif // SHARE_VM_LOGGING_LOGCONFIGURATION_HPP |