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"
27 #include "logging/logOutput.hpp"
28 #include "logging/logTag.hpp"
29 #include "logging/logTagSet.hpp"
30 #include "memory/allocation.inline.hpp"
31
32 LogTagSet* LogTagSet::_list = NULL;
33 size_t LogTagSet::_ntagsets = 0;
34
35 // This constructor is called only during static initialization.
36 // See the declaration in logTagSet.hpp for more information.
37 LogTagSet::LogTagSet(PrefixWriter prefix_writer, LogTagType t0, LogTagType t1, LogTagType t2, LogTagType t3, LogTagType t4)
38 : _next(_list), _write_prefix(prefix_writer) {
39 _tag[0] = t0;
40 _tag[1] = t1;
41 _tag[2] = t2;
42 _tag[3] = t3;
43 _tag[4] = t4;
44 for (_ntags = 0; _ntags < LogTag::MaxTags && _tag[_ntags] != LogTag::__NO_TAG; _ntags++) {
45 }
46 _list = this;
47 _ntagsets++;
48
49 // Set the default output to warning and error level for all new tagsets.
50 _output_list.set_output_level(LogOutput::Stderr, LogLevel::Default);
102 char buf[vwrite_buffer_size];
103 va_list saved_args; // For re-format on buf overflow.
104 va_copy(saved_args, args);
105 size_t prefix_len = _write_prefix(buf, sizeof(buf));
106 // Check that string fits in buffer; resize buffer if necessary
107 int ret = os::log_vsnprintf(buf + prefix_len, sizeof(buf) - prefix_len, fmt, args);
108 assert(ret >= 0, "Log message buffer issue");
109 if ((size_t)ret >= sizeof(buf)) {
110 size_t newbuf_len = prefix_len + ret + 1;
111 char* newbuf = NEW_C_HEAP_ARRAY(char, newbuf_len, mtLogging);
112 memcpy(newbuf, buf, prefix_len);
113 ret = os::log_vsnprintf(newbuf + prefix_len, newbuf_len - prefix_len, fmt, saved_args);
114 assert(ret >= 0, "Log message buffer issue");
115 log(level, newbuf);
116 FREE_C_HEAP_ARRAY(char, newbuf);
117 } else {
118 log(level, buf);
119 }
120 va_end(saved_args);
121 }
|
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"
27 #include "logging/logOutput.hpp"
28 #include "logging/logTag.hpp"
29 #include "logging/logTagSet.hpp"
30 #include "logging/logTagSetDescriptions.inline.hpp"
31 #include "memory/allocation.inline.hpp"
32 #include "utilities/ostream.hpp"
33
34 LogTagSet* LogTagSet::_list = NULL;
35 size_t LogTagSet::_ntagsets = 0;
36
37 // This constructor is called only during static initialization.
38 // See the declaration in logTagSet.hpp for more information.
39 LogTagSet::LogTagSet(PrefixWriter prefix_writer, LogTagType t0, LogTagType t1, LogTagType t2, LogTagType t3, LogTagType t4)
40 : _next(_list), _write_prefix(prefix_writer) {
41 _tag[0] = t0;
42 _tag[1] = t1;
43 _tag[2] = t2;
44 _tag[3] = t3;
45 _tag[4] = t4;
46 for (_ntags = 0; _ntags < LogTag::MaxTags && _tag[_ntags] != LogTag::__NO_TAG; _ntags++) {
47 }
48 _list = this;
49 _ntagsets++;
50
51 // Set the default output to warning and error level for all new tagsets.
52 _output_list.set_output_level(LogOutput::Stderr, LogLevel::Default);
104 char buf[vwrite_buffer_size];
105 va_list saved_args; // For re-format on buf overflow.
106 va_copy(saved_args, args);
107 size_t prefix_len = _write_prefix(buf, sizeof(buf));
108 // Check that string fits in buffer; resize buffer if necessary
109 int ret = os::log_vsnprintf(buf + prefix_len, sizeof(buf) - prefix_len, fmt, args);
110 assert(ret >= 0, "Log message buffer issue");
111 if ((size_t)ret >= sizeof(buf)) {
112 size_t newbuf_len = prefix_len + ret + 1;
113 char* newbuf = NEW_C_HEAP_ARRAY(char, newbuf_len, mtLogging);
114 memcpy(newbuf, buf, prefix_len);
115 ret = os::log_vsnprintf(newbuf + prefix_len, newbuf_len - prefix_len, fmt, saved_args);
116 assert(ret >= 0, "Log message buffer issue");
117 log(level, newbuf);
118 FREE_C_HEAP_ARRAY(char, newbuf);
119 } else {
120 log(level, buf);
121 }
122 va_end(saved_args);
123 }
124
125 static const size_t TagSetBufferSize = 128;
126
127 void LogTagSet::describe_tagsets(outputStream* out) {
128 out->print_cr("Described tag combinations:");
129 for (const LogTagSetDescription* d = tagset_descriptions; d->tagset != NULL; d++) {
130 char buf[TagSetBufferSize];
131 d->tagset->label(buf, sizeof(buf), "+");
132 out->print_cr(" %s: %s", buf, d->descr);
133 }
134 }
135
136 static int qsort_strcmp(const void* a, const void* b) {
137 return strcmp((*(const char**)a), (*(const char**)b));
138 }
139
140 void LogTagSet::list_all_tagsets(outputStream* out) {
141 char** tagset_labels = NEW_C_HEAP_ARRAY(char*, _ntagsets, mtLogging);
142
143 // Generate the list of tagset labels
144 size_t idx = 0;
145 for (LogTagSet* ts = first(); ts != NULL; ts = ts->next()) {
146 char buf[TagSetBufferSize];
147 ts->label(buf, sizeof(buf), "+");
148 tagset_labels[idx++] = os::strdup_check_oom(buf, mtLogging);
149 }
150 assert(idx == _ntagsets, "_ntagsets and list of tagsets not in sync");
151
152 // Sort them lexicographically
153 qsort(tagset_labels, _ntagsets, sizeof(*tagset_labels), qsort_strcmp);
154
155 // Print and then free the labels
156 out->print("All available tag sets: ");
157 for (idx = 0; idx < _ntagsets; idx++) {
158 out->print("%s%s", (idx == 0 ? "" : ", "), tagset_labels[idx]);
159 os::free(tagset_labels[idx]);
160 }
161 out->cr();
162 FREE_C_HEAP_ARRAY(char*, tagset_labels);
163 }
164
|