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 #ifndef SHARE_VM_LOGGING_LOGDECORATORS_HPP_
25 #define SHARE_VM_LOGGING_LOGDECORATORS_HPP_
26 #include "utilities/globalDefinitions.hpp"
27
28 // The list of available decorators:
29 // time - Current time and date in ISO-8601 format
30 // uptime - Time since the start of the JVM in seconds and milliseconds (e.g., 6.567s)
31 // timemillis - The same value as generated by System.currentTimeMillis()
32 // uptimemillis - Milliseconds since the JVM started
33 // timenanos - The same value as generated by System.nanoTime()
34 // uptimenanos - Nanoseconds since the JVM started
35 // pid - The process identifier
36 // tid - The thread identifier
37 // level - The level associated with the log message
38 // tags - The tag-set associated with the log message
39 #define DECORATOR_LIST \
40 DECORATOR(time, t) \
41 DECORATOR(uptime, u) \
42 DECORATOR(timemillis, tm) \
43 DECORATOR(uptimemillis, um) \
44 DECORATOR(timenanos, tn) \
45 DECORATOR(uptimenanos, un) \
46 DECORATOR(pid, p) \
47 DECORATOR(tid, ti) \
48 DECORATOR(level, l) \
49 DECORATOR(tags, tg)
50
51 // LogDecorators represents a selection of decorators that should be prepended to
52 // each log message for a given output. Decorators are always prepended in the order
53 // declared above. For example, logging with 'uptime, level, tags' decorators results in:
54 // [0,943s][info ][logging] message.
55 class LogDecorators {
56 public:
57 enum Decorator {
58 #define DECORATOR(name, abbr) name##_decorator,
59 DECORATOR_LIST
60 #undef DECORATOR
61 Count,
62 Invalid
63 };
64
65 private:
66 uint _decorators;
67 static const char* _name[][2];
68 static const uint DefaultDecoratorsMask = (1 << uptime_decorator) | (1 << level_decorator) | (1 << tags_decorator);
69
70 static uint mask(LogDecorators::Decorator decorator) {
71 return 1 << decorator;
72 }
73
74 public:
75 LogDecorators() : _decorators(DefaultDecoratorsMask) {
83 return _name[decorator][0];
84 }
85
86 static const char* abbreviation(LogDecorators::Decorator decorator) {
87 return _name[decorator][1];
88 }
89
90 static LogDecorators::Decorator from_string(const char* str);
91
92 void combine_with(const LogDecorators &source) {
93 _decorators |= source._decorators;
94 }
95
96 bool is_decorator(LogDecorators::Decorator decorator) const {
97 return (_decorators & mask(decorator)) != 0;
98 }
99
100 bool parse(const char* decorator_args, outputStream* errstream = NULL);
101 };
102
103 #endif
|
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 #ifndef SHARE_VM_LOGGING_LOGDECORATORS_HPP
25 #define SHARE_VM_LOGGING_LOGDECORATORS_HPP
26
27 #include "memory/allocation.hpp"
28 #include "utilities/globalDefinitions.hpp"
29
30 // The list of available decorators:
31 // time - Current time and date in ISO-8601 format
32 // 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 started
35 // timenanos - The same value as generated by System.nanoTime()
36 // uptimenanos - Nanoseconds since the JVM started
37 // pid - The process identifier
38 // tid - The thread identifier
39 // level - The level associated with the log message
40 // tags - The tag-set associated with the log message
41 #define DECORATOR_LIST \
42 DECORATOR(time, t) \
43 DECORATOR(uptime, u) \
44 DECORATOR(timemillis, tm) \
45 DECORATOR(uptimemillis, um) \
46 DECORATOR(timenanos, tn) \
47 DECORATOR(uptimenanos, un) \
48 DECORATOR(pid, p) \
49 DECORATOR(tid, ti) \
50 DECORATOR(level, l) \
51 DECORATOR(tags, tg)
52
53 // LogDecorators represents a selection of decorators that should be prepended to
54 // each log message for a given output. Decorators are always prepended in the order
55 // declared above. For example, logging with 'uptime, level, tags' decorators results in:
56 // [0,943s][info ][logging] message.
57 class LogDecorators VALUE_OBJ_CLASS_SPEC {
58 public:
59 enum Decorator {
60 #define DECORATOR(name, abbr) name##_decorator,
61 DECORATOR_LIST
62 #undef DECORATOR
63 Count,
64 Invalid
65 };
66
67 private:
68 uint _decorators;
69 static const char* _name[][2];
70 static const uint DefaultDecoratorsMask = (1 << uptime_decorator) | (1 << level_decorator) | (1 << tags_decorator);
71
72 static uint mask(LogDecorators::Decorator decorator) {
73 return 1 << decorator;
74 }
75
76 public:
77 LogDecorators() : _decorators(DefaultDecoratorsMask) {
85 return _name[decorator][0];
86 }
87
88 static const char* abbreviation(LogDecorators::Decorator decorator) {
89 return _name[decorator][1];
90 }
91
92 static LogDecorators::Decorator from_string(const char* str);
93
94 void combine_with(const LogDecorators &source) {
95 _decorators |= source._decorators;
96 }
97
98 bool is_decorator(LogDecorators::Decorator decorator) const {
99 return (_decorators & mask(decorator)) != 0;
100 }
101
102 bool parse(const char* decorator_args, outputStream* errstream = NULL);
103 };
104
105 #endif // SHARE_VM_LOGGING_LOGDECORATORS_HPP
|