1 /* src/toolbox/logging.c - contains logging functions
3 Copyright (C) 1996-2005, 2006 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 Contact: cacao@cacaojvm.org
27 Authors: Reinhard Grafl
29 Changes: Christian Thalinger
32 $Id: logging.c 4921 2006-05-15 14:24:36Z twisti $
46 #include "mm/memory.h"
47 #include "toolbox/logging.h"
48 #include "toolbox/util.h"
49 #include "vm/global.h"
50 #include "vm/statistics.h"
52 #if defined(ENABLE_THREADS)
53 # include "threads/native/threads.h"
57 /***************************************************************************
59 ***************************************************************************/
64 void log_init(const char *fname)
68 logfile = fopen(fname, "w");
74 /* log_start *******************************************************************
76 Writes the preleading LOG: text to the protocol file (if opened) or
79 *******************************************************************************/
84 #if defined(ENABLE_THREADS)
85 fprintf(logfile, "[%p] ", (void *) THREADOBJECT);
89 #if defined(ENABLE_THREADS)
90 fprintf(stdout, "LOG: [%p] ", (void *) THREADOBJECT);
92 fputs("LOG: ", stdout);
98 /* log_vprint ******************************************************************
100 Writes logtext to the protocol file (if opened) or to stdout.
102 *******************************************************************************/
104 static void log_vprint(const char *text, va_list ap)
107 vfprintf(logfile, text, ap);
109 vfprintf(stdout, text, ap);
113 /* log_print *******************************************************************
115 Writes logtext to the protocol file (if opened) or to stdout.
117 *******************************************************************************/
119 void log_print(const char *text, ...)
124 log_vprint(text, ap);
129 /* log_println *****************************************************************
131 Writes logtext to the protocol file (if opened) or to stdout with a
134 *******************************************************************************/
136 void log_println(const char *text, ...)
143 log_vprint(text, ap);
150 /* log_finish ******************************************************************
152 Finishes a logtext line with trailing newline and a fflush.
154 *******************************************************************************/
156 void log_finish(void)
169 /* log_message_utf *************************************************************
171 Outputs log text like this:
173 LOG: Creating class: java/lang/Object
175 *******************************************************************************/
177 void log_message_utf(const char *msg, utf *u)
182 len = strlen(msg) + utf_bytes(u) + strlen("0");
184 buf = MNEW(char, len);
191 MFREE(buf, char, len);
195 /* log_message_class ***********************************************************
197 Outputs log text like this:
199 LOG: Loading class: java/lang/Object
201 *******************************************************************************/
203 void log_message_class(const char *msg, classinfo *c)
205 log_message_utf(msg, c->name);
209 /* log_message_class_message_class *********************************************
211 Outputs log text like this:
213 LOG: Initialize super class java/lang/Object from java/lang/VMThread
215 *******************************************************************************/
217 void log_message_class_message_class(const char *msg1, classinfo *c1,
218 const char *msg2, classinfo *c2)
224 strlen(msg1) + utf_bytes(c1->name) +
225 strlen(msg2) + utf_bytes(c2->name) + strlen("0");
227 buf = MNEW(char, len);
230 utf_cat_classname(buf, c1->name);
232 utf_cat_classname(buf, c2->name);
236 MFREE(buf, char, len);
240 /* log_message_method **********************************************************
242 Outputs log text like this:
244 LOG: Compiling: java.lang.Object.clone()Ljava/lang/Object;
246 *******************************************************************************/
248 void log_message_method(const char *msg, methodinfo *m)
253 len = strlen(msg) + utf_bytes(m->class->name) + strlen(".") +
254 utf_bytes(m->name) + utf_bytes(m->descriptor) + strlen("0");
256 buf = MNEW(char, len);
259 utf_cat_classname(buf, m->class->name);
261 utf_cat(buf, m->name);
262 utf_cat(buf, m->descriptor);
266 MFREE(buf, char, len);
271 * These are local overrides for various environment variables in Emacs.
272 * Please do not remove this and leave it at the end of the file, where
273 * Emacs will automagically detect them.
274 * ---------------------------------------------------------------------
277 * indent-tabs-mode: t
281 * vim:noexpandtab:sw=4:ts=4: