2
* Copyright (c) 2015, 2023, Oracle and/or its affiliates. All rights reserved.
3
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
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.
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).
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.
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
25
#include "precompiled.hpp"
26
#include "logging/logSelectionList.hpp"
27
#include "logging/logTagSet.hpp"
28
#include "runtime/os.hpp"
30
static const char* DefaultExpressionString = "all";
32
bool LogSelectionList::verify_selections(outputStream* out) const {
35
for (size_t i = 0; i < _nselections; i++) {
36
if (_selections[i].tag_sets_selected() == 0) {
37
// Return immediately unless all invalid selections should be listed
42
out->print("No tag set matches selection:");
46
_selections[i].describe_tags_on(out);
49
_selections[i].suggest_similar_matching(out);
57
bool LogSelectionList::parse(const char* str, outputStream* errstream) {
59
if (str == nullptr || strcmp(str, "") == 0) {
60
str = DefaultExpressionString;
62
char* copy = os::strdup_check_oom(str, mtLogging);
63
// Split string on commas
64
for (char *comma_pos = copy, *cur = copy; success && comma_pos != nullptr; cur = comma_pos + 1) {
65
if (_nselections == MaxSelections) {
66
if (errstream != nullptr) {
67
errstream->print_cr("Can not have more than " SIZE_FORMAT " log selections in a single configuration.",
74
comma_pos = strchr(cur, ',');
75
if (comma_pos != nullptr) {
79
LogSelection selection = LogSelection::parse(cur, errstream);
80
if (selection == LogSelection::Invalid) {
84
_selections[_nselections++] = selection;
91
LogLevelType LogSelectionList::level_for(const LogTagSet& ts) const {
92
// Return NotMentioned if the given tagset isn't covered by this expression.
93
LogLevelType level = LogLevel::NotMentioned;
94
for (size_t i= 0; i < _nselections; i++) {
95
if (_selections[i].selects(ts)) {
96
level = _selections[i].level();