author | phh |
Sat, 30 Nov 2019 14:33:05 -0800 | |
changeset 59330 | 5b96c12f909d |
parent 49163 | 580bb0b85f63 |
permissions | -rw-r--r-- |
33097 | 1 |
/* |
49163
580bb0b85f63
8198554: Add fuzzy matching for log levels and tags when parsing -Xlog
mlarsson
parents:
47216
diff
changeset
|
2 |
* Copyright (c) 2015, 2018, 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 |
#include "precompiled.hpp" |
|
25 |
#include "logging/logLevel.hpp" |
|
26 |
#include "utilities/globalDefinitions.hpp" |
|
49163
580bb0b85f63
8198554: Add fuzzy matching for log levels and tags when parsing -Xlog
mlarsson
parents:
47216
diff
changeset
|
27 |
#include "utilities/stringUtils.hpp" |
33097 | 28 |
|
29 |
const char* LogLevel::_name[] = { |
|
30 |
"off", |
|
31 |
#define LOG_LEVEL(name, printname) #printname, |
|
32 |
LOG_LEVEL_LIST |
|
33 |
#undef LOG_LEVEL |
|
34 |
}; |
|
35 |
||
36 |
LogLevelType LogLevel::from_string(const char* str) { |
|
37 |
for (uint i = 0; i < Count; i++) { |
|
38 |
if (strcasecmp(str, _name[i]) == 0) { |
|
39 |
return static_cast<LogLevelType>(i); |
|
40 |
} |
|
41 |
} |
|
42 |
return Invalid; |
|
43 |
} |
|
49163
580bb0b85f63
8198554: Add fuzzy matching for log levels and tags when parsing -Xlog
mlarsson
parents:
47216
diff
changeset
|
44 |
|
580bb0b85f63
8198554: Add fuzzy matching for log levels and tags when parsing -Xlog
mlarsson
parents:
47216
diff
changeset
|
45 |
LogLevelType LogLevel::fuzzy_match(const char *level) { |
580bb0b85f63
8198554: Add fuzzy matching for log levels and tags when parsing -Xlog
mlarsson
parents:
47216
diff
changeset
|
46 |
size_t len = strlen(level); |
580bb0b85f63
8198554: Add fuzzy matching for log levels and tags when parsing -Xlog
mlarsson
parents:
47216
diff
changeset
|
47 |
LogLevelType match = LogLevel::Invalid; |
580bb0b85f63
8198554: Add fuzzy matching for log levels and tags when parsing -Xlog
mlarsson
parents:
47216
diff
changeset
|
48 |
double best = 0.4; // required similarity to be considered a match |
580bb0b85f63
8198554: Add fuzzy matching for log levels and tags when parsing -Xlog
mlarsson
parents:
47216
diff
changeset
|
49 |
for (uint i = 1; i < Count; i++) { |
580bb0b85f63
8198554: Add fuzzy matching for log levels and tags when parsing -Xlog
mlarsson
parents:
47216
diff
changeset
|
50 |
LogLevelType cur = static_cast<LogLevelType>(i); |
580bb0b85f63
8198554: Add fuzzy matching for log levels and tags when parsing -Xlog
mlarsson
parents:
47216
diff
changeset
|
51 |
const char* levelname = LogLevel::name(cur); |
580bb0b85f63
8198554: Add fuzzy matching for log levels and tags when parsing -Xlog
mlarsson
parents:
47216
diff
changeset
|
52 |
double score = StringUtils::similarity(level, len, levelname, strlen(levelname)); |
580bb0b85f63
8198554: Add fuzzy matching for log levels and tags when parsing -Xlog
mlarsson
parents:
47216
diff
changeset
|
53 |
if (score >= best) { |
580bb0b85f63
8198554: Add fuzzy matching for log levels and tags when parsing -Xlog
mlarsson
parents:
47216
diff
changeset
|
54 |
match = cur; |
580bb0b85f63
8198554: Add fuzzy matching for log levels and tags when parsing -Xlog
mlarsson
parents:
47216
diff
changeset
|
55 |
best= score; |
580bb0b85f63
8198554: Add fuzzy matching for log levels and tags when parsing -Xlog
mlarsson
parents:
47216
diff
changeset
|
56 |
} |
580bb0b85f63
8198554: Add fuzzy matching for log levels and tags when parsing -Xlog
mlarsson
parents:
47216
diff
changeset
|
57 |
} |
580bb0b85f63
8198554: Add fuzzy matching for log levels and tags when parsing -Xlog
mlarsson
parents:
47216
diff
changeset
|
58 |
return match; |
580bb0b85f63
8198554: Add fuzzy matching for log levels and tags when parsing -Xlog
mlarsson
parents:
47216
diff
changeset
|
59 |
} |