Path: blob/master/src/hotspot/share/logging/logDecorators.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*/23#include "precompiled.hpp"24#include "logging/logDecorators.hpp"25#include "runtime/os.hpp"2627const LogDecorators LogDecorators::None = LogDecorators(0);2829const char* LogDecorators::_name[][2] = {30#define DECORATOR(n, a) {#n, #a},31DECORATOR_LIST32#undef DECORATOR33};3435LogDecorators::Decorator LogDecorators::from_string(const char* str) {36for (size_t i = 0; i < Count; i++) {37Decorator d = static_cast<Decorator>(i);38if (strcasecmp(str, name(d)) == 0 || strcasecmp(str, abbreviation(d)) == 0) {39return d;40}41}42return Invalid;43}4445bool LogDecorators::parse(const char* decorator_args, outputStream* errstream) {46if (decorator_args == NULL || strlen(decorator_args) == 0) {47_decorators = DefaultDecoratorsMask;48return true;49}5051if (strcasecmp(decorator_args, "none") == 0 ) {52_decorators = 0;53return true;54}5556bool result = true;57uint tmp_decorators = 0;58char* args_copy = os::strdup_check_oom(decorator_args, mtLogging);59char* token = args_copy;60char* comma_pos;61do {62comma_pos = strchr(token, ',');63if (comma_pos != NULL) {64*comma_pos = '\0';65}66Decorator d = from_string(token);67if (d == Invalid) {68if (errstream != NULL) {69errstream->print_cr("Invalid decorator '%s'.", token);70}71result = false;72break;73}74tmp_decorators |= mask(d);75token = comma_pos + 1;76} while (comma_pos != NULL);77os::free(args_copy);78if (result) {79_decorators = tmp_decorators;80}81return result;82}838485