author | mlarsson |
Mon, 09 May 2016 15:46:12 +0200 | |
changeset 38263 | a7488329ad27 |
parent 37464 | 5373bbadb433 |
child 38292 | 73a0be9b2f47 |
permissions | -rw-r--r-- |
33097 | 1 |
/* |
2 |
* Copyright (c) 2015, 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 |
#include "precompiled.hpp" |
|
25 |
#include "logging/logDecorations.hpp" |
|
26 |
#include "logging/logLevel.hpp" |
|
38263
a7488329ad27
8145934: Make ttyLocker equivalent for Unified Logging framework
mlarsson
parents:
37464
diff
changeset
|
27 |
#include "logging/logMessageBuffer.hpp" |
33097 | 28 |
#include "logging/logOutput.hpp" |
29 |
#include "logging/logTag.hpp" |
|
30 |
#include "logging/logTagSet.hpp" |
|
37247 | 31 |
#include "memory/allocation.inline.hpp" |
33097 | 32 |
|
33 |
LogTagSet* LogTagSet::_list = NULL; |
|
34 |
size_t LogTagSet::_ntagsets = 0; |
|
35 |
||
36 |
// This constructor is called only during static initialization. |
|
37 |
// See the declaration in logTagSet.hpp for more information. |
|
37247 | 38 |
LogTagSet::LogTagSet(PrefixWriter prefix_writer, LogTagType t0, LogTagType t1, LogTagType t2, LogTagType t3, LogTagType t4) |
39 |
: _next(_list), _write_prefix(prefix_writer) { |
|
33097 | 40 |
_tag[0] = t0; |
41 |
_tag[1] = t1; |
|
42 |
_tag[2] = t2; |
|
43 |
_tag[3] = t3; |
|
44 |
_tag[4] = t4; |
|
45 |
for (_ntags = 0; _ntags < LogTag::MaxTags && _tag[_ntags] != LogTag::__NO_TAG; _ntags++) { |
|
46 |
} |
|
47 |
_list = this; |
|
48 |
_ntagsets++; |
|
49 |
||
50 |
// Set the default output to warning and error level for all new tagsets. |
|
51 |
_output_list.set_output_level(LogOutput::Stderr, LogLevel::Default); |
|
52 |
} |
|
53 |
||
54 |
void LogTagSet::update_decorators(const LogDecorators& decorator) { |
|
55 |
LogDecorators new_decorators = decorator; |
|
56 |
for (LogOutputList::Iterator it = _output_list.iterator(); it != _output_list.end(); it++) { |
|
57 |
new_decorators.combine_with((*it)->decorators()); |
|
58 |
} |
|
59 |
_decorators = new_decorators; |
|
60 |
} |
|
61 |
||
62 |
bool LogTagSet::has_output(const LogOutput* output) { |
|
63 |
for (LogOutputList::Iterator it = _output_list.iterator(); it != _output_list.end(); it++) { |
|
64 |
if (*it == output) { |
|
65 |
return true; |
|
66 |
} |
|
67 |
} |
|
68 |
return false; |
|
69 |
} |
|
70 |
||
71 |
void LogTagSet::log(LogLevelType level, const char* msg) { |
|
72 |
LogDecorations decorations(level, *this, _decorators); |
|
73 |
for (LogOutputList::Iterator it = _output_list.iterator(level); it != _output_list.end(); it++) { |
|
74 |
(*it)->write(decorations, msg); |
|
75 |
} |
|
76 |
} |
|
77 |
||
38263
a7488329ad27
8145934: Make ttyLocker equivalent for Unified Logging framework
mlarsson
parents:
37464
diff
changeset
|
78 |
void LogTagSet::log(const LogMessageBuffer& msg) { |
a7488329ad27
8145934: Make ttyLocker equivalent for Unified Logging framework
mlarsson
parents:
37464
diff
changeset
|
79 |
LogDecorations decorations(LogLevel::Invalid, *this, _decorators); |
a7488329ad27
8145934: Make ttyLocker equivalent for Unified Logging framework
mlarsson
parents:
37464
diff
changeset
|
80 |
for (LogOutputList::Iterator it = _output_list.iterator(msg.least_detailed_level()); it != _output_list.end(); it++) { |
a7488329ad27
8145934: Make ttyLocker equivalent for Unified Logging framework
mlarsson
parents:
37464
diff
changeset
|
81 |
(*it)->write(msg.iterator(it.level(), decorations)); |
a7488329ad27
8145934: Make ttyLocker equivalent for Unified Logging framework
mlarsson
parents:
37464
diff
changeset
|
82 |
} |
a7488329ad27
8145934: Make ttyLocker equivalent for Unified Logging framework
mlarsson
parents:
37464
diff
changeset
|
83 |
} |
a7488329ad27
8145934: Make ttyLocker equivalent for Unified Logging framework
mlarsson
parents:
37464
diff
changeset
|
84 |
|
34316
4d876653d940
8142952: Unified Logging framework does not allow multiple -Xlog: arguments.
mlarsson
parents:
33097
diff
changeset
|
85 |
int LogTagSet::label(char* buf, size_t len, const char* separator) const { |
33097 | 86 |
int tot_written = 0; |
87 |
for (size_t i = 0; i < _ntags; i++) { |
|
88 |
int written = jio_snprintf(buf + tot_written, len - tot_written, "%s%s", |
|
34316
4d876653d940
8142952: Unified Logging framework does not allow multiple -Xlog: arguments.
mlarsson
parents:
33097
diff
changeset
|
89 |
(i == 0 ? "" : separator), |
33097 | 90 |
LogTag::name(_tag[i])); |
91 |
if (written < 0) { |
|
92 |
return -1; |
|
93 |
} |
|
94 |
tot_written += written; |
|
95 |
} |
|
96 |
return tot_written; |
|
97 |
} |
|
37247 | 98 |
|
99 |
void LogTagSet::write(LogLevelType level, const char* fmt, ...) { |
|
100 |
va_list args; |
|
101 |
va_start(args, fmt); |
|
102 |
vwrite(level, fmt, args); |
|
103 |
va_end(args); |
|
104 |
} |
|
105 |
||
106 |
const size_t vwrite_buffer_size = 512; |
|
107 |
||
108 |
void LogTagSet::vwrite(LogLevelType level, const char* fmt, va_list args) { |
|
37464
5373bbadb433
8153845: UL log write method missing essential assert
rehn
parents:
37247
diff
changeset
|
109 |
assert(level >= LogLevel::First && level <= LogLevel::Last, "Log level:%d is incorrect", level); |
37247 | 110 |
char buf[vwrite_buffer_size]; |
111 |
va_list saved_args; // For re-format on buf overflow. |
|
112 |
va_copy(saved_args, args); |
|
113 |
size_t prefix_len = _write_prefix(buf, sizeof(buf)); |
|
114 |
// Check that string fits in buffer; resize buffer if necessary |
|
115 |
int ret = os::log_vsnprintf(buf + prefix_len, sizeof(buf) - prefix_len, fmt, args); |
|
116 |
assert(ret >= 0, "Log message buffer issue"); |
|
117 |
if ((size_t)ret >= sizeof(buf)) { |
|
118 |
size_t newbuf_len = prefix_len + ret + 1; |
|
119 |
char* newbuf = NEW_C_HEAP_ARRAY(char, newbuf_len, mtLogging); |
|
120 |
memcpy(newbuf, buf, prefix_len); |
|
121 |
ret = os::log_vsnprintf(newbuf + prefix_len, newbuf_len - prefix_len, fmt, saved_args); |
|
122 |
assert(ret >= 0, "Log message buffer issue"); |
|
123 |
log(level, newbuf); |
|
124 |
FREE_C_HEAP_ARRAY(char, newbuf); |
|
125 |
} else { |
|
126 |
log(level, buf); |
|
127 |
} |
|
128 |
va_end(saved_args); |
|
129 |
} |