1/*
2 * Copyright (c) 2015, 2018, 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
25#include "precompiled.hpp"
26#include "logging/logSelectionList.hpp"
27#include "logging/logTagSet.hpp"
28#include "runtime/arguments.hpp"
29#include "runtime/os.inline.hpp"
30
31static const char* DefaultExpressionString = "all";
32
33bool LogSelectionList::verify_selections(outputStream* out) const {
34 bool valid = true;
35
36 for (size_t i = 0; i < _nselections; i++) {
37 if (_selections[i].tag_sets_selected() == 0) {
38 // Return immediately unless all invalid selections should be listed
39 if (out == NULL) {
40 return false;
41 }
42
43 out->print("No tag set matches selection:");
44 valid = false;
45
46 char buf[256];
47 _selections[i].describe_tags(buf, sizeof(buf));
48 out->print(" %s. ", buf);
49
50 _selections[i].suggest_similar_matching(out);
51 out->cr();
52 }
53 }
54 return valid;
55}
56
57
58bool LogSelectionList::parse(const char* str, outputStream* errstream) {
59 bool success = true;
60 if (str == NULL || strcmp(str, "") == 0) {
61 str = DefaultExpressionString;
62 }
63 char* copy = os::strdup_check_oom(str, mtLogging);
64 // Split string on commas
65 for (char *comma_pos = copy, *cur = copy; success && comma_pos != NULL; cur = comma_pos + 1) {
66 if (_nselections == MaxSelections) {
67 if (errstream != NULL) {
68 errstream->print_cr("Can not have more than " SIZE_FORMAT " log selections in a single configuration.",
69 MaxSelections);
70 }
71 success = false;
72 break;
73 }
74
75 comma_pos = strchr(cur, ',');
76 if (comma_pos != NULL) {
77 *comma_pos = '\0';
78 }
79
80 LogSelection selection = LogSelection::parse(cur, errstream);
81 if (selection == LogSelection::Invalid) {
82 success = false;
83 break;
84 }
85 _selections[_nselections++] = selection;
86 }
87
88 os::free(copy);
89 return success;
90}
91
92LogLevelType LogSelectionList::level_for(const LogTagSet& ts) const {
93 // Return NotMentioned if the given tagset isn't covered by this expression.
94 LogLevelType level = LogLevel::NotMentioned;
95 for (size_t i= 0; i < _nselections; i++) {
96 if (_selections[i].selects(ts)) {
97 level = _selections[i].level();
98 }
99 }
100 return level;
101}
102