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
25 $Id: logging.c 7246 2007-01-29 18:49:05Z twisti $
38 #include "mm/memory.h"
39 #include "toolbox/logging.h"
40 #include "toolbox/util.h"
41 #include "vm/global.h"
43 #if defined(ENABLE_STATISTICS)
44 # include "vmcore/statistics.h"
48 #if defined(ENABLE_THREADS)
49 # include "threads/native/threads.h"
54 /***************************************************************************
56 ***************************************************************************/
61 void log_init(const char *fname)
65 logfile = fopen(fname, "w");
71 /* log_start *******************************************************************
73 Writes the preleading LOG: text to the protocol file (if opened) or
76 *******************************************************************************/
81 #if defined(ENABLE_THREADS)
83 /* fprintf(logfile, "[%p] ", (void *) threads_get_current_threadobject()); */
87 #if defined(ENABLE_THREADS)
89 /* fprintf(stdout, "LOG: [%p] ", (void *) threads_get_current_threadobject()); */
91 fputs("LOG: ", stdout);
97 /* log_vprint ******************************************************************
99 Writes logtext to the protocol file (if opened) or to stdout.
101 *******************************************************************************/
103 void log_vprint(const char *text, va_list ap)
106 vfprintf(logfile, text, ap);
108 vfprintf(stdout, text, ap);
112 /* log_print *******************************************************************
114 Writes logtext to the protocol file (if opened) or to stdout.
116 *******************************************************************************/
118 void log_print(const char *text, ...)
123 log_vprint(text, ap);
128 /* log_println *****************************************************************
130 Writes logtext to the protocol file (if opened) or to stdout with a
133 *******************************************************************************/
135 void log_println(const char *text, ...)
142 log_vprint(text, ap);
149 /* log_finish ******************************************************************
151 Finishes a logtext line with trailing newline and a fflush.
153 *******************************************************************************/
155 void log_finish(void)
168 /* log_message_utf *************************************************************
170 Outputs log text like this:
172 LOG: Creating class: java/lang/Object
174 *******************************************************************************/
176 void log_message_utf(const char *msg, utf *u)
181 len = strlen(msg) + utf_bytes(u) + strlen("0");
183 buf = MNEW(char, len);
190 MFREE(buf, char, len);
194 /* log_message_class ***********************************************************
196 Outputs log text like this:
198 LOG: Loading class: java/lang/Object
200 *******************************************************************************/
202 void log_message_class(const char *msg, classinfo *c)
204 log_message_utf(msg, c->name);
208 /* log_message_class_message_class *********************************************
210 Outputs log text like this:
212 LOG: Initialize super class java/lang/Object from java/lang/VMThread
214 *******************************************************************************/
216 void log_message_class_message_class(const char *msg1, classinfo *c1,
217 const char *msg2, classinfo *c2)
223 strlen(msg1) + utf_bytes(c1->name) +
224 strlen(msg2) + utf_bytes(c2->name) + strlen("0");
226 buf = MNEW(char, len);
229 utf_cat_classname(buf, c1->name);
231 utf_cat_classname(buf, c2->name);
235 MFREE(buf, char, len);
239 /* log_message_method **********************************************************
241 Outputs log text like this:
243 LOG: Compiling: java.lang.Object.clone()Ljava/lang/Object;
245 *******************************************************************************/
247 void log_message_method(const char *msg, methodinfo *m)
252 len = strlen(msg) + utf_bytes(m->class->name) + strlen(".") +
253 utf_bytes(m->name) + utf_bytes(m->descriptor) + strlen("0");
255 buf = MNEW(char, len);
258 utf_cat_classname(buf, m->class->name);
260 utf_cat(buf, m->name);
261 utf_cat(buf, m->descriptor);
265 MFREE(buf, char, len);
270 * These are local overrides for various environment variables in Emacs.
271 * Please do not remove this and leave it at the end of the file, where
272 * Emacs will automagically detect them.
273 * ---------------------------------------------------------------------
276 * indent-tabs-mode: t
280 * vim:noexpandtab:sw=4:ts=4: