Path: blob/master/src/hotspot/share/logging/logDecorators.hpp
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#ifndef SHARE_LOGGING_LOGDECORATORS_HPP24#define SHARE_LOGGING_LOGDECORATORS_HPP2526#include "utilities/globalDefinitions.hpp"2728class outputStream;2930// The list of available decorators:31// time - Current time and date in ISO-8601 format32// uptime - Time since the start of the JVM in seconds and milliseconds (e.g., 6.567s)33// timemillis - The same value as generated by System.currentTimeMillis()34// uptimemillis - Milliseconds since the JVM started35// timenanos - The same value as generated by System.nanoTime()36// uptimenanos - Nanoseconds since the JVM started37// hostname - The hostname38// pid - The process identifier39// tid - The thread identifier40// level - The level associated with the log message41// tags - The tag-set associated with the log message42#define DECORATOR_LIST \43DECORATOR(time, t) \44DECORATOR(utctime, utc) \45DECORATOR(uptime, u) \46DECORATOR(timemillis, tm) \47DECORATOR(uptimemillis, um) \48DECORATOR(timenanos, tn) \49DECORATOR(uptimenanos, un) \50DECORATOR(hostname, hn) \51DECORATOR(pid, p) \52DECORATOR(tid, ti) \53DECORATOR(level, l) \54DECORATOR(tags, tg)5556// LogDecorators represents a selection of decorators that should be prepended to57// each log message for a given output. Decorators are always prepended in the order58// declared above. For example, logging with 'uptime, level, tags' decorators results in:59// [0,943s][info ][logging] message.60class LogDecorators {61public:62enum Decorator {63#define DECORATOR(name, abbr) name##_decorator,64DECORATOR_LIST65#undef DECORATOR66Count,67Invalid68};6970private:71uint _decorators;72static const char* _name[][2];73static const uint DefaultDecoratorsMask = (1 << uptime_decorator) | (1 << level_decorator) | (1 << tags_decorator);7475static uint mask(LogDecorators::Decorator decorator) {76return 1 << decorator;77}7879LogDecorators(uint mask) : _decorators(mask) {80}8182public:83static const LogDecorators None;8485LogDecorators() : _decorators(DefaultDecoratorsMask) {86}8788void clear() {89_decorators = 0;90}9192static const char* name(LogDecorators::Decorator decorator) {93return _name[decorator][0];94}9596static const char* abbreviation(LogDecorators::Decorator decorator) {97return _name[decorator][1];98}99100static LogDecorators::Decorator from_string(const char* str);101102void combine_with(const LogDecorators &source) {103_decorators |= source._decorators;104}105106bool is_empty() const {107return _decorators == 0;108}109110bool is_decorator(LogDecorators::Decorator decorator) const {111return (_decorators & mask(decorator)) != 0;112}113114bool parse(const char* decorator_args, outputStream* errstream = NULL);115};116117#endif // SHARE_LOGGING_LOGDECORATORS_HPP118119120