author | rehn |
Fri, 08 Apr 2016 15:36:34 +0200 | |
changeset 37463 | a4581cbe32cd |
parent 37247 | bdbfe42632cb |
child 38263 | a7488329ad27 |
permissions | -rw-r--r-- |
33097 | 1 |
/* |
37247 | 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_LOGTAGSET_HPP |
|
25 |
#define SHARE_VM_LOGGING_LOGTAGSET_HPP |
|
26 |
||
27 |
#include "logging/logDecorators.hpp" |
|
28 |
#include "logging/logLevel.hpp" |
|
29 |
#include "logging/logOutputList.hpp" |
|
37247 | 30 |
#include "logging/logPrefix.hpp" |
33097 | 31 |
#include "logging/logTag.hpp" |
32 |
#include "utilities/globalDefinitions.hpp" |
|
33 |
||
34 |
// The tagset represents a combination of tags that occur in a log call somewhere. |
|
35 |
// Tagsets are created automatically by the LogTagSetMappings and should never be |
|
36 |
// instantiated directly somewhere else. |
|
37 |
class LogTagSet VALUE_OBJ_CLASS_SPEC { |
|
38 |
private: |
|
39 |
static LogTagSet* _list; |
|
40 |
static size_t _ntagsets; |
|
41 |
||
42 |
LogTagSet* const _next; |
|
43 |
size_t _ntags; |
|
44 |
LogTagType _tag[LogTag::MaxTags]; |
|
45 |
||
46 |
LogOutputList _output_list; |
|
47 |
LogDecorators _decorators; |
|
48 |
||
37247 | 49 |
typedef size_t (*PrefixWriter)(char* buf, size_t size); |
50 |
PrefixWriter _write_prefix; |
|
51 |
||
33097 | 52 |
// Keep constructor private to prevent incorrect instantiations of this class. |
53 |
// Only LogTagSetMappings can create/contain instances of this class. |
|
54 |
// The constructor links all tagsets together in a global list of tagsets. |
|
55 |
// This list is used during configuration to be able to update all tagsets |
|
56 |
// and their configurations to reflect the new global log configuration. |
|
37247 | 57 |
LogTagSet(PrefixWriter prefix_writer, LogTagType t0, LogTagType t1, LogTagType t2, LogTagType t3, LogTagType t4); |
33097 | 58 |
|
37247 | 59 |
template <LogTagType T0, LogTagType T1, LogTagType T2, LogTagType T3, LogTagType T4, LogTagType GuardTag> |
33097 | 60 |
friend class LogTagSetMapping; |
61 |
||
62 |
public: |
|
63 |
static LogTagSet* first() { |
|
64 |
return _list; |
|
65 |
} |
|
66 |
||
37463
a4581cbe32cd
8153731: Increase max tag combinations for UL expression (config)
rehn
parents:
37247
diff
changeset
|
67 |
static size_t ntagsets() { |
a4581cbe32cd
8153731: Increase max tag combinations for UL expression (config)
rehn
parents:
37247
diff
changeset
|
68 |
return _ntagsets; |
a4581cbe32cd
8153731: Increase max tag combinations for UL expression (config)
rehn
parents:
37247
diff
changeset
|
69 |
} |
a4581cbe32cd
8153731: Increase max tag combinations for UL expression (config)
rehn
parents:
37247
diff
changeset
|
70 |
|
33097 | 71 |
LogTagSet* next() { |
72 |
return _next; |
|
73 |
} |
|
74 |
||
75 |
size_t ntags() const { |
|
76 |
return _ntags; |
|
77 |
} |
|
78 |
||
37200 | 79 |
LogTagType tag(size_t idx) const { |
80 |
return _tag[idx]; |
|
81 |
} |
|
82 |
||
33097 | 83 |
bool contains(LogTagType tag) const { |
84 |
for (size_t i = 0; _tag[i] != LogTag::__NO_TAG; i++) { |
|
85 |
if (tag == _tag[i]) { |
|
86 |
return true; |
|
87 |
} |
|
88 |
} |
|
89 |
return false; |
|
90 |
} |
|
91 |
||
34316
4d876653d940
8142952: Unified Logging framework does not allow multiple -Xlog: arguments.
mlarsson
parents:
33097
diff
changeset
|
92 |
LogLevelType level_for(const LogOutput* output) const { |
4d876653d940
8142952: Unified Logging framework does not allow multiple -Xlog: arguments.
mlarsson
parents:
33097
diff
changeset
|
93 |
return _output_list.level_for(output); |
4d876653d940
8142952: Unified Logging framework does not allow multiple -Xlog: arguments.
mlarsson
parents:
33097
diff
changeset
|
94 |
} |
4d876653d940
8142952: Unified Logging framework does not allow multiple -Xlog: arguments.
mlarsson
parents:
33097
diff
changeset
|
95 |
|
33097 | 96 |
void set_output_level(LogOutput* output, LogLevelType level) { |
97 |
_output_list.set_output_level(output, level); |
|
98 |
} |
|
99 |
||
100 |
// Refresh the decorators for this tagset to contain the decorators for all |
|
101 |
// of its current outputs combined with the given decorators. |
|
34316
4d876653d940
8142952: Unified Logging framework does not allow multiple -Xlog: arguments.
mlarsson
parents:
33097
diff
changeset
|
102 |
void update_decorators(const LogDecorators& decorator = LogDecorators::None); |
33097 | 103 |
|
34316
4d876653d940
8142952: Unified Logging framework does not allow multiple -Xlog: arguments.
mlarsson
parents:
33097
diff
changeset
|
104 |
int label(char *buf, size_t len, const char* separator = ",") const; |
33097 | 105 |
bool has_output(const LogOutput* output); |
37241
b9961c99c356
8152538: UL doesn't inline the LogTagSet::is_level check
stefank
parents:
37200
diff
changeset
|
106 |
|
b9961c99c356
8152538: UL doesn't inline the LogTagSet::is_level check
stefank
parents:
37200
diff
changeset
|
107 |
// The implementation of this function is put here to ensure |
b9961c99c356
8152538: UL doesn't inline the LogTagSet::is_level check
stefank
parents:
37200
diff
changeset
|
108 |
// that it is inline:able by the log_is_enabled(level, ...) macro. |
b9961c99c356
8152538: UL doesn't inline the LogTagSet::is_level check
stefank
parents:
37200
diff
changeset
|
109 |
bool is_level(LogLevelType level) const { |
b9961c99c356
8152538: UL doesn't inline the LogTagSet::is_level check
stefank
parents:
37200
diff
changeset
|
110 |
return _output_list.is_level(level); |
b9961c99c356
8152538: UL doesn't inline the LogTagSet::is_level check
stefank
parents:
37200
diff
changeset
|
111 |
} |
33097 | 112 |
void log(LogLevelType level, const char* msg); |
37247 | 113 |
|
114 |
ATTRIBUTE_PRINTF(3, 4) |
|
115 |
void write(LogLevelType level, const char* fmt, ...); |
|
116 |
||
117 |
template <LogLevelType Level> |
|
118 |
ATTRIBUTE_PRINTF(2, 3) |
|
119 |
void write(const char* fmt, ...) { |
|
120 |
va_list args; |
|
121 |
va_start(args, fmt); |
|
122 |
vwrite(Level, fmt, args); |
|
123 |
va_end(args); |
|
124 |
} |
|
125 |
||
126 |
ATTRIBUTE_PRINTF(3, 0) |
|
127 |
void vwrite(LogLevelType level, const char* fmt, va_list args); |
|
33097 | 128 |
}; |
129 |
||
130 |
template <LogTagType T0, LogTagType T1 = LogTag::__NO_TAG, LogTagType T2 = LogTag::__NO_TAG, |
|
37247 | 131 |
LogTagType T3 = LogTag::__NO_TAG, LogTagType T4 = LogTag::__NO_TAG, |
132 |
LogTagType GuardTag = LogTag::__NO_TAG> |
|
33097 | 133 |
class LogTagSetMapping : public AllStatic { |
134 |
private: |
|
37247 | 135 |
// Verify number of logging tags does not exceed maximum supported. |
136 |
STATIC_ASSERT(GuardTag == LogTag::__NO_TAG); |
|
33097 | 137 |
static LogTagSet _tagset; |
138 |
||
139 |
public: |
|
140 |
static LogTagSet& tagset() { |
|
141 |
return _tagset; |
|
142 |
} |
|
143 |
}; |
|
144 |
||
145 |
// Instantiate the static field _tagset for all tagsets that are used for logging somewhere. |
|
146 |
// (This must be done here rather than the .cpp file because it's a template.) |
|
147 |
// Each combination of tags used as template arguments to the Log class somewhere (via macro or not) |
|
148 |
// will instantiate the LogTagSetMapping template, which in turn creates the static field for that |
|
149 |
// tagset. This _tagset contains the configuration for those tags. |
|
37247 | 150 |
template <LogTagType T0, LogTagType T1, LogTagType T2, LogTagType T3, LogTagType T4, LogTagType GuardTag> |
151 |
LogTagSet LogTagSetMapping<T0, T1, T2, T3, T4, GuardTag>::_tagset(&LogPrefix<T0, T1, T2, T3, T4>::prefix, T0, T1, T2, T3, T4); |
|
33097 | 152 |
|
153 |
#endif // SHARE_VM_LOGGING_LOGTAGSET_HPP |