author | rehn |
Mon, 04 Apr 2016 15:05:52 +0200 | |
changeset 37247 | bdbfe42632cb |
parent 35852 | 15ca44d4ae0c |
child 40884 | 0e28c526f5d3 |
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 |
||
32 |
bool LogTagLevelExpression::parse(const char* str, outputStream* errstream) { |
|
33 |
bool success = true; |
|
34 |
if (str == NULL || strcmp(str, "") == 0) { |
|
35 |
str = DefaultExpressionString; |
|
36 |
} |
|
37 |
char* copy = os::strdup_check_oom(str, mtLogging); |
|
38 |
// Split string on commas |
|
39 |
for (char *comma_pos = copy, *cur = copy; success && comma_pos != NULL; cur = comma_pos + 1) { |
|
40 |
if (_ncombinations == MaxCombinations) { |
|
41 |
if (errstream != NULL) { |
|
42 |
errstream->print_cr("Can not have more than " SIZE_FORMAT " tag combinations in a what-expression.", |
|
43 |
MaxCombinations); |
|
44 |
} |
|
45 |
success = false; |
|
46 |
break; |
|
47 |
} |
|
48 |
||
49 |
comma_pos = strchr(cur, ','); |
|
50 |
if (comma_pos != NULL) { |
|
51 |
*comma_pos = '\0'; |
|
52 |
} |
|
53 |
||
54 |
// Parse the level, if specified |
|
55 |
LogLevelType level = LogLevel::Unspecified; |
|
56 |
char* equals = strchr(cur, '='); |
|
57 |
if (equals != NULL) { |
|
58 |
level = LogLevel::from_string(equals + 1); |
|
59 |
if (level == LogLevel::Invalid) { |
|
60 |
if (errstream != NULL) { |
|
61 |
errstream->print_cr("Invalid level '%s' in what-expression.", equals + 1); |
|
62 |
} |
|
63 |
success = false; |
|
64 |
break; |
|
65 |
} |
|
66 |
*equals = '\0'; // now ignore "=level" part of substr |
|
67 |
} |
|
68 |
set_level(level); |
|
69 |
||
70 |
// Parse special tags such as 'all' |
|
71 |
if (strcmp(cur, "all") == 0) { |
|
72 |
set_allow_other_tags(); |
|
73 |
new_combination(); |
|
74 |
continue; |
|
75 |
} |
|
76 |
||
77 |
// Check for '*' suffix |
|
78 |
char* asterisk_pos = strchr(cur, '*'); |
|
79 |
if (asterisk_pos != NULL && asterisk_pos[1] == '\0') { |
|
80 |
set_allow_other_tags(); |
|
81 |
*asterisk_pos = '\0'; |
|
82 |
} |
|
83 |
||
84 |
// Parse the tag expression (t1+t2+...+tn) |
|
85 |
char* plus_pos; |
|
86 |
char* cur_tag = cur; |
|
87 |
do { |
|
88 |
plus_pos = strchr(cur_tag, '+'); |
|
89 |
if (plus_pos != NULL) { |
|
90 |
*plus_pos = '\0'; |
|
91 |
} |
|
92 |
LogTagType tag = LogTag::from_string(cur_tag); |
|
93 |
if (tag == LogTag::__NO_TAG) { |
|
94 |
if (errstream != NULL) { |
|
95 |
errstream->print_cr("Invalid tag '%s' in what-expression.", cur_tag); |
|
96 |
} |
|
97 |
success = false; |
|
98 |
break; |
|
99 |
} |
|
100 |
if (_ntags == LogTag::MaxTags) { |
|
101 |
if (errstream != NULL) { |
|
102 |
errstream->print_cr("Tag combination exceeds the maximum of " SIZE_FORMAT " tags.", |
|
103 |
LogTag::MaxTags); |
|
104 |
} |
|
105 |
success = false; |
|
106 |
break; |
|
107 |
} |
|
108 |
add_tag(tag); |
|
109 |
cur_tag = plus_pos + 1; |
|
110 |
} while (plus_pos != NULL); |
|
111 |
||
112 |
new_combination(); |
|
113 |
} |
|
114 |
||
34316
4d876653d940
8142952: Unified Logging framework does not allow multiple -Xlog: arguments.
mlarsson
parents:
33097
diff
changeset
|
115 |
os::free(copy); |
33097 | 116 |
return success; |
117 |
} |
|
118 |
||
119 |
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
|
120 |
// 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
|
121 |
LogLevelType level = LogLevel::NotMentioned; |
33097 | 122 |
for (size_t combination = 0; combination < _ncombinations; combination++) { |
123 |
bool contains_all = true; |
|
124 |
size_t tag_idx; |
|
125 |
for (tag_idx = 0; tag_idx < LogTag::MaxTags && _tags[combination][tag_idx] != LogTag::__NO_TAG; tag_idx++) { |
|
126 |
if (!ts.contains(_tags[combination][tag_idx])) { |
|
127 |
contains_all = false; |
|
128 |
break; |
|
129 |
} |
|
130 |
} |
|
131 |
// All tags in the expression must be part of the tagset, |
|
132 |
// and either the expression allows other tags (has a wildcard), |
|
133 |
// or the number of tags in the expression and tagset must match. |
|
134 |
if (contains_all && (_allow_other_tags[combination] || tag_idx == ts.ntags())) { |
|
135 |
level = _level[combination]; |
|
136 |
} |
|
137 |
} |
|
138 |
return level; |
|
139 |
} |