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 7685 2007-04-11 08:21:06Z 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 /***************************************************************************
50 ***************************************************************************/
55 void log_init(const char *fname)
59 logfile = fopen(fname, "w");
65 /* log_start *******************************************************************
67 Writes the preleading LOG: text to the protocol file (if opened) or
70 *******************************************************************************/
72 /* ATTENTION: Don't include threads-common.h, because we can't
73 bootstrap this file in that case (missing java_lang_Thread.h).
74 Instead we declare threads_get_current_threadobject differently: */
76 /* #if defined(ENABLE_THREADS) */
77 /* # include "threads/threads-common.h" */
80 extern ptrint threads_get_current_tid(void);
85 #if defined(ENABLE_THREADS)
88 tid = threads_get_current_tid();
92 #if defined(ENABLE_THREADS)
93 # if SIZEOF_VOID_P == 8
94 fprintf(logfile, "[0x%016lx] ", tid );
96 fprintf(logfile, "[0x%08x] ", tid);
101 #if defined(ENABLE_THREADS)
102 # if SIZEOF_VOID_P == 8
103 fprintf(stdout, "LOG: [0x%016lx] ", tid);
105 fprintf(stdout, "LOG: [0x%08x] ", tid);
108 fputs("LOG: ", stdout);
114 /* log_vprint ******************************************************************
116 Writes logtext to the protocol file (if opened) or to stdout.
118 *******************************************************************************/
120 void log_vprint(const char *text, va_list ap)
123 vfprintf(logfile, text, ap);
125 vfprintf(stdout, text, ap);
129 /* log_print *******************************************************************
131 Writes logtext to the protocol file (if opened) or to stdout.
133 *******************************************************************************/
135 void log_print(const char *text, ...)
140 log_vprint(text, ap);
145 /* log_println *****************************************************************
147 Writes logtext to the protocol file (if opened) or to stdout with a
150 *******************************************************************************/
152 void log_println(const char *text, ...)
159 log_vprint(text, ap);
166 /* log_finish ******************************************************************
168 Finishes a logtext line with trailing newline and a fflush.
170 *******************************************************************************/
172 void log_finish(void)
175 fputs("\n", logfile);
185 /* log_message_utf *************************************************************
187 Outputs log text like this:
189 LOG: Creating class: java/lang/Object
191 *******************************************************************************/
193 void log_message_utf(const char *msg, utf *u)
198 len = strlen(msg) + utf_bytes(u) + strlen("0");
200 buf = MNEW(char, len);
207 MFREE(buf, char, len);
211 /* log_message_class ***********************************************************
213 Outputs log text like this:
215 LOG: Loading class: java/lang/Object
217 *******************************************************************************/
219 void log_message_class(const char *msg, classinfo *c)
221 log_message_utf(msg, c->name);
225 /* log_message_class_message_class *********************************************
227 Outputs log text like this:
229 LOG: Initialize super class java/lang/Object from java/lang/VMThread
231 *******************************************************************************/
233 void log_message_class_message_class(const char *msg1, classinfo *c1,
234 const char *msg2, classinfo *c2)
240 strlen(msg1) + utf_bytes(c1->name) +
241 strlen(msg2) + utf_bytes(c2->name) + strlen("0");
243 buf = MNEW(char, len);
246 utf_cat_classname(buf, c1->name);
248 utf_cat_classname(buf, c2->name);
252 MFREE(buf, char, len);
256 /* log_message_method **********************************************************
258 Outputs log text like this:
260 LOG: Compiling: java.lang.Object.clone()Ljava/lang/Object;
262 *******************************************************************************/
264 void log_message_method(const char *msg, methodinfo *m)
269 len = strlen(msg) + utf_bytes(m->class->name) + strlen(".") +
270 utf_bytes(m->name) + utf_bytes(m->descriptor) + strlen("0");
272 buf = MNEW(char, len);
275 utf_cat_classname(buf, m->class->name);
277 utf_cat(buf, m->name);
278 utf_cat(buf, m->descriptor);
282 MFREE(buf, char, len);
287 * These are local overrides for various environment variables in Emacs.
288 * Please do not remove this and leave it at the end of the file, where
289 * Emacs will automagically detect them.
290 * ---------------------------------------------------------------------
293 * indent-tabs-mode: t
297 * vim:noexpandtab:sw=4:ts=4: