1 /* src/toolbox/logging.c - contains logging functions
3 Copyright (C) 1996-2005, 2006, 2007 R. Grafl, A. Krall, C. Kruegel,
4 C. Oates, R. Obermaisser, M. Platter, M. Probst, S. Ring,
5 E. Steiner, C. Thalinger, D. Thuernbeck, P. Tomsich, C. Ullrich,
6 J. Wenninger, Institut f. Computersprachen - TU Wien
8 This file is part of CACAO.
10 This program is free software; you can redistribute it and/or
11 modify it under the terms of the GNU General Public License as
12 published by the Free Software Foundation; either version 2, or (at
13 your option) any later version.
15 This program is distributed in the hope that it will be useful, but
16 WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 General Public License for more details.
20 You should have received a copy of the GNU General Public License
21 along with this program; if not, write to the Free Software
22 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
36 #include "mm/memory.h"
37 #include "threads/threads-common.h"
38 #include "toolbox/logging.h"
39 #include "toolbox/util.h"
40 #include "vm/global.h"
42 #if defined(ENABLE_STATISTICS)
43 # include "vmcore/statistics.h"
47 /***************************************************************************
49 ***************************************************************************/
54 void log_init(const char *fname)
58 logfile = fopen(fname, "w");
64 /* log_start *******************************************************************
66 Writes the preleading LOG: text to the protocol file (if opened) or
69 *******************************************************************************/
73 #if defined(ENABLE_THREADS)
76 tid = threads_get_current_tid();
80 #if defined(ENABLE_THREADS)
81 # if SIZEOF_VOID_P == 8
82 fprintf(logfile, "[0x%016lx] ", tid );
84 fprintf(logfile, "[0x%08x] ", tid);
89 #if defined(ENABLE_THREADS)
90 # if SIZEOF_VOID_P == 8
91 fprintf(stdout, "LOG: [0x%016lx] ", tid);
93 fprintf(stdout, "LOG: [0x%08x] ", tid);
96 fputs("LOG: ", stdout);
102 /* log_vprint ******************************************************************
104 Writes logtext to the protocol file (if opened) or to stdout.
106 *******************************************************************************/
108 void log_vprint(const char *text, va_list ap)
111 vfprintf(logfile, text, ap);
113 vfprintf(stdout, text, ap);
117 /* log_print *******************************************************************
119 Writes logtext to the protocol file (if opened) or to stdout.
121 *******************************************************************************/
123 void log_print(const char *text, ...)
128 log_vprint(text, ap);
133 /* log_println *****************************************************************
135 Writes logtext to the protocol file (if opened) or to stdout with a
138 *******************************************************************************/
140 void log_println(const char *text, ...)
147 log_vprint(text, ap);
154 /* log_finish ******************************************************************
156 Finishes a logtext line with trailing newline and a fflush.
158 *******************************************************************************/
160 void log_finish(void)
163 fputs("\n", logfile);
173 /* log_message_utf *************************************************************
175 Outputs log text like this:
177 LOG: Creating class: java/lang/Object
179 *******************************************************************************/
181 void log_message_utf(const char *msg, utf *u)
186 len = strlen(msg) + utf_bytes(u) + strlen("0");
188 buf = MNEW(char, len);
195 MFREE(buf, char, len);
199 /* log_message_class ***********************************************************
201 Outputs log text like this:
203 LOG: Loading class: java/lang/Object
205 *******************************************************************************/
207 void log_message_class(const char *msg, classinfo *c)
209 log_message_utf(msg, c->name);
213 /* log_message_class_message_class *********************************************
215 Outputs log text like this:
217 LOG: Initialize super class java/lang/Object from java/lang/VMThread
219 *******************************************************************************/
221 void log_message_class_message_class(const char *msg1, classinfo *c1,
222 const char *msg2, classinfo *c2)
228 strlen(msg1) + utf_bytes(c1->name) +
229 strlen(msg2) + utf_bytes(c2->name) + strlen("0");
231 buf = MNEW(char, len);
234 utf_cat_classname(buf, c1->name);
236 utf_cat_classname(buf, c2->name);
240 MFREE(buf, char, len);
244 /* log_message_method **********************************************************
246 Outputs log text like this:
248 LOG: Compiling: java.lang.Object.clone()Ljava/lang/Object;
250 *******************************************************************************/
252 void log_message_method(const char *msg, methodinfo *m)
257 len = strlen(msg) + utf_bytes(m->class->name) + strlen(".") +
258 utf_bytes(m->name) + utf_bytes(m->descriptor) + strlen("0");
260 buf = MNEW(char, len);
263 utf_cat_classname(buf, m->class->name);
265 utf_cat(buf, m->name);
266 utf_cat(buf, m->descriptor);
270 MFREE(buf, char, len);
275 * These are local overrides for various environment variables in Emacs.
276 * Please do not remove this and leave it at the end of the file, where
277 * Emacs will automagically detect them.
278 * ---------------------------------------------------------------------
281 * indent-tabs-mode: t
285 * vim:noexpandtab:sw=4:ts=4: