Path: blob/master/src/hotspot/share/logging/logSelectionList.cpp
40930 views
/*1* Copyright (c) 2015, 2021, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*22*/2324#include "precompiled.hpp"25#include "logging/logSelectionList.hpp"26#include "logging/logTagSet.hpp"27#include "runtime/os.hpp"2829static const char* DefaultExpressionString = "all";3031bool LogSelectionList::verify_selections(outputStream* out) const {32bool valid = true;3334for (size_t i = 0; i < _nselections; i++) {35if (_selections[i].tag_sets_selected() == 0) {36// Return immediately unless all invalid selections should be listed37if (out == NULL) {38return false;39}4041out->print("No tag set matches selection:");42valid = false;4344char buf[256];45_selections[i].describe_tags(buf, sizeof(buf));46out->print(" %s. ", buf);4748_selections[i].suggest_similar_matching(out);49out->cr();50}51}52return valid;53}545556bool LogSelectionList::parse(const char* str, outputStream* errstream) {57bool success = true;58if (str == NULL || strcmp(str, "") == 0) {59str = DefaultExpressionString;60}61char* copy = os::strdup_check_oom(str, mtLogging);62// Split string on commas63for (char *comma_pos = copy, *cur = copy; success && comma_pos != NULL; cur = comma_pos + 1) {64if (_nselections == MaxSelections) {65if (errstream != NULL) {66errstream->print_cr("Can not have more than " SIZE_FORMAT " log selections in a single configuration.",67MaxSelections);68}69success = false;70break;71}7273comma_pos = strchr(cur, ',');74if (comma_pos != NULL) {75*comma_pos = '\0';76}7778LogSelection selection = LogSelection::parse(cur, errstream);79if (selection == LogSelection::Invalid) {80success = false;81break;82}83_selections[_nselections++] = selection;84}8586os::free(copy);87return success;88}8990LogLevelType LogSelectionList::level_for(const LogTagSet& ts) const {91// Return NotMentioned if the given tagset isn't covered by this expression.92LogLevelType level = LogLevel::NotMentioned;93for (size_t i= 0; i < _nselections; i++) {94if (_selections[i].selects(ts)) {95level = _selections[i].level();96}97}98return level;99}100101102