author | coleenp |
Tue, 31 Oct 2017 11:55:09 -0400 | |
changeset 47765 | b7c7428eaab9 |
parent 47216 | 71c04702a3d5 |
permissions | -rw-r--r-- |
33097 | 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 |
#include "precompiled.hpp" |
|
25 |
#include "logging/logTagLevelExpression.hpp" |
|
26 |
#include "logging/logTagSet.hpp" |
|
27 |
#include "runtime/arguments.hpp" |
|
28 |
#include "runtime/os.inline.hpp" |
|
29 |
||
30 |
const char* LogTagLevelExpression::DefaultExpressionString = "all"; |
|
31 |
||
40884
0e28c526f5d3
8150894: Unused -Xlog tag sequences are silently ignored.
mlarsson
parents:
35852
diff
changeset
|
32 |
static bool matches_tagset(const LogTagType tags[], |
0e28c526f5d3
8150894: Unused -Xlog tag sequences are silently ignored.
mlarsson
parents:
35852
diff
changeset
|
33 |
bool allow_other_tags, |
0e28c526f5d3
8150894: Unused -Xlog tag sequences are silently ignored.
mlarsson
parents:
35852
diff
changeset
|
34 |
const LogTagSet& ts) { |
0e28c526f5d3
8150894: Unused -Xlog tag sequences are silently ignored.
mlarsson
parents:
35852
diff
changeset
|
35 |
bool contains_all = true; |
0e28c526f5d3
8150894: Unused -Xlog tag sequences are silently ignored.
mlarsson
parents:
35852
diff
changeset
|
36 |
size_t tag_idx; |
0e28c526f5d3
8150894: Unused -Xlog tag sequences are silently ignored.
mlarsson
parents:
35852
diff
changeset
|
37 |
for (tag_idx = 0; tag_idx < LogTag::MaxTags && tags[tag_idx] != LogTag::__NO_TAG; tag_idx++) { |
0e28c526f5d3
8150894: Unused -Xlog tag sequences are silently ignored.
mlarsson
parents:
35852
diff
changeset
|
38 |
if (!ts.contains(tags[tag_idx])) { |
0e28c526f5d3
8150894: Unused -Xlog tag sequences are silently ignored.
mlarsson
parents:
35852
diff
changeset
|
39 |
contains_all = false; |
0e28c526f5d3
8150894: Unused -Xlog tag sequences are silently ignored.
mlarsson
parents:
35852
diff
changeset
|
40 |
break; |
0e28c526f5d3
8150894: Unused -Xlog tag sequences are silently ignored.
mlarsson
parents:
35852
diff
changeset
|
41 |
} |
0e28c526f5d3
8150894: Unused -Xlog tag sequences are silently ignored.
mlarsson
parents:
35852
diff
changeset
|
42 |
} |
0e28c526f5d3
8150894: Unused -Xlog tag sequences are silently ignored.
mlarsson
parents:
35852
diff
changeset
|
43 |
// All tags in the expression must be part of the tagset, |
0e28c526f5d3
8150894: Unused -Xlog tag sequences are silently ignored.
mlarsson
parents:
35852
diff
changeset
|
44 |
// and either the expression allows other tags (has a wildcard), |
0e28c526f5d3
8150894: Unused -Xlog tag sequences are silently ignored.
mlarsson
parents:
35852
diff
changeset
|
45 |
// or the number of tags in the expression and tagset must match. |
0e28c526f5d3
8150894: Unused -Xlog tag sequences are silently ignored.
mlarsson
parents:
35852
diff
changeset
|
46 |
return contains_all && (allow_other_tags || tag_idx == ts.ntags()); |
0e28c526f5d3
8150894: Unused -Xlog tag sequences are silently ignored.
mlarsson
parents:
35852
diff
changeset
|
47 |
} |
0e28c526f5d3
8150894: Unused -Xlog tag sequences are silently ignored.
mlarsson
parents:
35852
diff
changeset
|
48 |
|
0e28c526f5d3
8150894: Unused -Xlog tag sequences are silently ignored.
mlarsson
parents:
35852
diff
changeset
|
49 |
bool LogTagLevelExpression::verify_tagsets(outputStream* out) const { |
0e28c526f5d3
8150894: Unused -Xlog tag sequences are silently ignored.
mlarsson
parents:
35852
diff
changeset
|
50 |
bool valid = true; |
0e28c526f5d3
8150894: Unused -Xlog tag sequences are silently ignored.
mlarsson
parents:
35852
diff
changeset
|
51 |
|
0e28c526f5d3
8150894: Unused -Xlog tag sequences are silently ignored.
mlarsson
parents:
35852
diff
changeset
|
52 |
for (size_t i = 0; i < _ncombinations; i++) { |
0e28c526f5d3
8150894: Unused -Xlog tag sequences are silently ignored.
mlarsson
parents:
35852
diff
changeset
|
53 |
bool matched = false; |
0e28c526f5d3
8150894: Unused -Xlog tag sequences are silently ignored.
mlarsson
parents:
35852
diff
changeset
|
54 |
for (LogTagSet* ts = LogTagSet::first(); ts != NULL; ts = ts->next()) { |
0e28c526f5d3
8150894: Unused -Xlog tag sequences are silently ignored.
mlarsson
parents:
35852
diff
changeset
|
55 |
if (matches_tagset(_tags[i], _allow_other_tags[i], *ts)) { |
0e28c526f5d3
8150894: Unused -Xlog tag sequences are silently ignored.
mlarsson
parents:
35852
diff
changeset
|
56 |
matched = true; |
0e28c526f5d3
8150894: Unused -Xlog tag sequences are silently ignored.
mlarsson
parents:
35852
diff
changeset
|
57 |
break; |
0e28c526f5d3
8150894: Unused -Xlog tag sequences are silently ignored.
mlarsson
parents:
35852
diff
changeset
|
58 |
} |
0e28c526f5d3
8150894: Unused -Xlog tag sequences are silently ignored.
mlarsson
parents:
35852
diff
changeset
|
59 |
} |
0e28c526f5d3
8150894: Unused -Xlog tag sequences are silently ignored.
mlarsson
parents:
35852
diff
changeset
|
60 |
|
0e28c526f5d3
8150894: Unused -Xlog tag sequences are silently ignored.
mlarsson
parents:
35852
diff
changeset
|
61 |
if (!matched) { |
0e28c526f5d3
8150894: Unused -Xlog tag sequences are silently ignored.
mlarsson
parents:
35852
diff
changeset
|
62 |
// If this was the first invalid combination, write the message header |
0e28c526f5d3
8150894: Unused -Xlog tag sequences are silently ignored.
mlarsson
parents:
35852
diff
changeset
|
63 |
if (valid && out != NULL) { |
0e28c526f5d3
8150894: Unused -Xlog tag sequences are silently ignored.
mlarsson
parents:
35852
diff
changeset
|
64 |
out->print("No tag set matches selection(s): "); |
0e28c526f5d3
8150894: Unused -Xlog tag sequences are silently ignored.
mlarsson
parents:
35852
diff
changeset
|
65 |
} |
0e28c526f5d3
8150894: Unused -Xlog tag sequences are silently ignored.
mlarsson
parents:
35852
diff
changeset
|
66 |
valid = false; |
0e28c526f5d3
8150894: Unused -Xlog tag sequences are silently ignored.
mlarsson
parents:
35852
diff
changeset
|
67 |
|
0e28c526f5d3
8150894: Unused -Xlog tag sequences are silently ignored.
mlarsson
parents:
35852
diff
changeset
|
68 |
// Break as soon as possible unless listing all invalid combinations |
0e28c526f5d3
8150894: Unused -Xlog tag sequences are silently ignored.
mlarsson
parents:
35852
diff
changeset
|
69 |
if (out == NULL) { |
0e28c526f5d3
8150894: Unused -Xlog tag sequences are silently ignored.
mlarsson
parents:
35852
diff
changeset
|
70 |
break; |
0e28c526f5d3
8150894: Unused -Xlog tag sequences are silently ignored.
mlarsson
parents:
35852
diff
changeset
|
71 |
} |
0e28c526f5d3
8150894: Unused -Xlog tag sequences are silently ignored.
mlarsson
parents:
35852
diff
changeset
|
72 |
|
0e28c526f5d3
8150894: Unused -Xlog tag sequences are silently ignored.
mlarsson
parents:
35852
diff
changeset
|
73 |
// List the combination on the outputStream |
0e28c526f5d3
8150894: Unused -Xlog tag sequences are silently ignored.
mlarsson
parents:
35852
diff
changeset
|
74 |
for (size_t t = 0; t < LogTag::MaxTags && _tags[i][t] != LogTag::__NO_TAG; t++) { |
0e28c526f5d3
8150894: Unused -Xlog tag sequences are silently ignored.
mlarsson
parents:
35852
diff
changeset
|
75 |
out->print("%s%s", (t == 0 ? "" : "+"), LogTag::name(_tags[i][t])); |
0e28c526f5d3
8150894: Unused -Xlog tag sequences are silently ignored.
mlarsson
parents:
35852
diff
changeset
|
76 |
} |
0e28c526f5d3
8150894: Unused -Xlog tag sequences are silently ignored.
mlarsson
parents:
35852
diff
changeset
|
77 |
if (_allow_other_tags[i]) { |
0e28c526f5d3
8150894: Unused -Xlog tag sequences are silently ignored.
mlarsson
parents:
35852
diff
changeset
|
78 |
out->print("*"); |
0e28c526f5d3
8150894: Unused -Xlog tag sequences are silently ignored.
mlarsson
parents:
35852
diff
changeset
|
79 |
} |
0e28c526f5d3
8150894: Unused -Xlog tag sequences are silently ignored.
mlarsson
parents:
35852
diff
changeset
|
80 |
out->print(" "); |
0e28c526f5d3
8150894: Unused -Xlog tag sequences are silently ignored.
mlarsson
parents:
35852
diff
changeset
|
81 |
} |
0e28c526f5d3
8150894: Unused -Xlog tag sequences are silently ignored.
mlarsson
parents:
35852
diff
changeset
|
82 |
} |
0e28c526f5d3
8150894: Unused -Xlog tag sequences are silently ignored.
mlarsson
parents:
35852
diff
changeset
|
83 |
|
0e28c526f5d3
8150894: Unused -Xlog tag sequences are silently ignored.
mlarsson
parents:
35852
diff
changeset
|
84 |
if (!valid && out != NULL) { |
0e28c526f5d3
8150894: Unused -Xlog tag sequences are silently ignored.
mlarsson
parents:
35852
diff
changeset
|
85 |
out->cr(); |
0e28c526f5d3
8150894: Unused -Xlog tag sequences are silently ignored.
mlarsson
parents:
35852
diff
changeset
|
86 |
} |
0e28c526f5d3
8150894: Unused -Xlog tag sequences are silently ignored.
mlarsson
parents:
35852
diff
changeset
|
87 |
|
0e28c526f5d3
8150894: Unused -Xlog tag sequences are silently ignored.
mlarsson
parents:
35852
diff
changeset
|
88 |
return valid; |
0e28c526f5d3
8150894: Unused -Xlog tag sequences are silently ignored.
mlarsson
parents:
35852
diff
changeset
|
89 |
} |
0e28c526f5d3
8150894: Unused -Xlog tag sequences are silently ignored.
mlarsson
parents:
35852
diff
changeset
|
90 |
|
33097 | 91 |
bool LogTagLevelExpression::parse(const char* str, outputStream* errstream) { |
92 |
bool success = true; |
|
93 |
if (str == NULL || strcmp(str, "") == 0) { |
|
94 |
str = DefaultExpressionString; |
|
95 |
} |
|
96 |
char* copy = os::strdup_check_oom(str, mtLogging); |
|
97 |
// Split string on commas |
|
98 |
for (char *comma_pos = copy, *cur = copy; success && comma_pos != NULL; cur = comma_pos + 1) { |
|
99 |
if (_ncombinations == MaxCombinations) { |
|
100 |
if (errstream != NULL) { |
|
101 |
errstream->print_cr("Can not have more than " SIZE_FORMAT " tag combinations in a what-expression.", |
|
102 |
MaxCombinations); |
|
103 |
} |
|
104 |
success = false; |
|
105 |
break; |
|
106 |
} |
|
107 |
||
108 |
comma_pos = strchr(cur, ','); |
|
109 |
if (comma_pos != NULL) { |
|
110 |
*comma_pos = '\0'; |
|
111 |
} |
|
112 |
||
113 |
// Parse the level, if specified |
|
114 |
LogLevelType level = LogLevel::Unspecified; |
|
115 |
char* equals = strchr(cur, '='); |
|
116 |
if (equals != NULL) { |
|
117 |
level = LogLevel::from_string(equals + 1); |
|
118 |
if (level == LogLevel::Invalid) { |
|
119 |
if (errstream != NULL) { |
|
120 |
errstream->print_cr("Invalid level '%s' in what-expression.", equals + 1); |
|
121 |
} |
|
122 |
success = false; |
|
123 |
break; |
|
124 |
} |
|
125 |
*equals = '\0'; // now ignore "=level" part of substr |
|
126 |
} |
|
127 |
set_level(level); |
|
128 |
||
129 |
// Parse special tags such as 'all' |
|
130 |
if (strcmp(cur, "all") == 0) { |
|
131 |
set_allow_other_tags(); |
|
132 |
new_combination(); |
|
133 |
continue; |
|
134 |
} |
|
135 |
||
136 |
// Check for '*' suffix |
|
137 |
char* asterisk_pos = strchr(cur, '*'); |
|
138 |
if (asterisk_pos != NULL && asterisk_pos[1] == '\0') { |
|
139 |
set_allow_other_tags(); |
|
140 |
*asterisk_pos = '\0'; |
|
141 |
} |
|
142 |
||
143 |
// Parse the tag expression (t1+t2+...+tn) |
|
144 |
char* plus_pos; |
|
145 |
char* cur_tag = cur; |
|
146 |
do { |
|
147 |
plus_pos = strchr(cur_tag, '+'); |
|
148 |
if (plus_pos != NULL) { |
|
149 |
*plus_pos = '\0'; |
|
150 |
} |
|
151 |
LogTagType tag = LogTag::from_string(cur_tag); |
|
152 |
if (tag == LogTag::__NO_TAG) { |
|
153 |
if (errstream != NULL) { |
|
154 |
errstream->print_cr("Invalid tag '%s' in what-expression.", cur_tag); |
|
155 |
} |
|
156 |
success = false; |
|
157 |
break; |
|
158 |
} |
|
159 |
if (_ntags == LogTag::MaxTags) { |
|
160 |
if (errstream != NULL) { |
|
161 |
errstream->print_cr("Tag combination exceeds the maximum of " SIZE_FORMAT " tags.", |
|
162 |
LogTag::MaxTags); |
|
163 |
} |
|
164 |
success = false; |
|
165 |
break; |
|
166 |
} |
|
40913
072bdbb90c13
8165215: Setting same UL tag multiple times matches wrong tagset
rehn
parents:
40884
diff
changeset
|
167 |
if (!add_tag(tag)) { |
072bdbb90c13
8165215: Setting same UL tag multiple times matches wrong tagset
rehn
parents:
40884
diff
changeset
|
168 |
if (errstream != NULL) { |
072bdbb90c13
8165215: Setting same UL tag multiple times matches wrong tagset
rehn
parents:
40884
diff
changeset
|
169 |
errstream->print_cr("Tag combination have duplicate tag '%s' in what-expression.", |
072bdbb90c13
8165215: Setting same UL tag multiple times matches wrong tagset
rehn
parents:
40884
diff
changeset
|
170 |
cur_tag); |
072bdbb90c13
8165215: Setting same UL tag multiple times matches wrong tagset
rehn
parents:
40884
diff
changeset
|
171 |
} |
072bdbb90c13
8165215: Setting same UL tag multiple times matches wrong tagset
rehn
parents:
40884
diff
changeset
|
172 |
success = false; |
072bdbb90c13
8165215: Setting same UL tag multiple times matches wrong tagset
rehn
parents:
40884
diff
changeset
|
173 |
break; |
072bdbb90c13
8165215: Setting same UL tag multiple times matches wrong tagset
rehn
parents:
40884
diff
changeset
|
174 |
} |
33097 | 175 |
cur_tag = plus_pos + 1; |
176 |
} while (plus_pos != NULL); |
|
177 |
||
178 |
new_combination(); |
|
179 |
} |
|
180 |
||
34316
4d876653d940
8142952: Unified Logging framework does not allow multiple -Xlog: arguments.
mlarsson
parents:
33097
diff
changeset
|
181 |
os::free(copy); |
33097 | 182 |
return success; |
183 |
} |
|
184 |
||
185 |
LogLevelType LogTagLevelExpression::level_for(const LogTagSet& ts) const { |
|
34316
4d876653d940
8142952: Unified Logging framework does not allow multiple -Xlog: arguments.
mlarsson
parents:
33097
diff
changeset
|
186 |
// Return NotMentioned if the given tagset isn't covered by this expression. |
4d876653d940
8142952: Unified Logging framework does not allow multiple -Xlog: arguments.
mlarsson
parents:
33097
diff
changeset
|
187 |
LogLevelType level = LogLevel::NotMentioned; |
33097 | 188 |
for (size_t combination = 0; combination < _ncombinations; combination++) { |
40884
0e28c526f5d3
8150894: Unused -Xlog tag sequences are silently ignored.
mlarsson
parents:
35852
diff
changeset
|
189 |
if (matches_tagset(_tags[combination], _allow_other_tags[combination], ts)) { |
33097 | 190 |
level = _level[combination]; |
191 |
} |
|
192 |
} |
|
193 |
return level; |
|
194 |
} |
|
40884
0e28c526f5d3
8150894: Unused -Xlog tag sequences are silently ignored.
mlarsson
parents:
35852
diff
changeset
|
195 |