1 /* src/toolbox/logging.c - contains logging functions
3 Copyright (C) 1996-2005 R. Grafl, A. Krall, C. Kruegel, C. Oates,
4 R. Obermaisser, M. Platter, M. Probst, S. Ring, E. Steiner,
5 C. Thalinger, D. Thuernbeck, P. Tomsich, C. Ullrich, J. Wenninger,
6 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., 59 Temple Place - Suite 330, Boston, MA
25 Contact: cacao@complang.tuwien.ac.at
27 Authors: Reinhard Grafl
29 Changes: Christian Thalinger
31 $Id: logging.c 3829 2005-12-01 19:47:56Z twisti $
44 #include "mm/memory.h"
45 #include "toolbox/logging.h"
46 #include "toolbox/util.h"
47 #include "vm/global.h"
48 #include "vm/statistics.h"
50 #if defined(USE_THREADS)
51 # if defined(NATIVE_THREADS)
52 # include "threads/native/threads.h"
57 /***************************************************************************
59 ***************************************************************************/
64 void log_init(const char *fname)
68 logfile = fopen(fname, "w");
74 /* dolog ***********************************************************************
76 Writes logtext to the protocol file (if opened) or to stdout.
78 *******************************************************************************/
80 void dolog(const char *text, ...)
85 #if defined(USE_THREADS) && defined(NATIVE_THREADS)
86 fprintf(logfile, "[%p] ", (void *) THREADOBJECT);
90 vfprintf(logfile, text, ap);
96 #if defined(USE_THREADS) && defined(NATIVE_THREADS)
97 fprintf(stdout, "LOG: [%p] ", (void *) THREADOBJECT);
99 fputs("LOG: ", stdout);
103 vfprintf(stdout, text, ap);
106 fprintf(stdout, "\n");
113 /******************** Function: dolog_plain *******************************
115 Writes logtext to the protocol file (if opened) or to stdout.
117 **************************************************************************/
119 void dolog_plain(const char *txt, ...)
121 char logtext[MAXLOGTEXT];
125 vsprintf(logtext, txt, ap);
129 fprintf(logfile, "%s", logtext);
133 fprintf(stdout,"%s", logtext);
139 /********************* Function: log_text ********************************/
141 void log_text(const char *text)
147 /******************** Function: log_plain *******************************/
149 void log_plain(const char *text)
151 dolog_plain("%s", text);
155 /****************** Function: get_logfile *******************************/
157 FILE *get_logfile(void)
159 return (logfile) ? logfile : stdout;
163 /****************** Function: log_flush *********************************/
167 fflush(get_logfile());
171 /********************* Function: log_nl *********************************/
176 fflush(get_logfile());
180 /* log_message_utf *************************************************************
182 Outputs log text like this:
184 LOG: Creating class: java/lang/Object
186 *******************************************************************************/
188 void log_message_utf(const char *msg, utf *u)
193 len = strlen(msg) + utf_strlen(u) + strlen("0");
195 buf = MNEW(char, len);
202 MFREE(buf, char, len);
206 /* log_message_class ***********************************************************
208 Outputs log text like this:
210 LOG: Loading class: java/lang/Object
212 *******************************************************************************/
214 void log_message_class(const char *msg, classinfo *c)
216 log_message_utf(msg, c->name);
220 /* log_message_class_message_class *********************************************
222 Outputs log text like this:
224 LOG: Initialize super class java/lang/Object from java/lang/VMThread
226 *******************************************************************************/
228 void log_message_class_message_class(const char *msg1, classinfo *c1,
229 const char *msg2, classinfo *c2)
235 strlen(msg1) + utf_strlen(c1->name) +
236 strlen(msg2) + utf_strlen(c2->name) + strlen("0");
238 buf = MNEW(char, len);
241 utf_strcat(buf, c1->name);
243 utf_strcat(buf, c2->name);
247 MFREE(buf, char, len);
251 /* log_message_method **********************************************************
253 Outputs log text like this:
255 LOG: Compiling: java.lang.Object.clone()Ljava/lang/Object;
257 *******************************************************************************/
259 void log_message_method(const char *msg, methodinfo *m)
264 len = strlen(msg) + utf_strlen(m->class->name) + strlen(".") +
265 utf_strlen(m->name) + utf_strlen(m->descriptor) + strlen("0");
267 buf = MNEW(char, len);
270 utf_strcat_classname(buf, m->class->name);
272 utf_strcat(buf, m->name);
273 utf_strcat(buf, m->descriptor);
277 MFREE(buf, char, len);
281 /* log_utf *********************************************************************
285 *******************************************************************************/
289 char buf[MAXLOGTEXT];
295 /* log_plain_utf ***************************************************************
297 Log utf symbol (without printing "LOG: " and newline).
299 *******************************************************************************/
301 void log_plain_utf(utf *u)
303 char buf[MAXLOGTEXT];
305 dolog_plain("%s", buf);
310 * These are local overrides for various environment variables in Emacs.
311 * Please do not remove this and leave it at the end of the file, where
312 * Emacs will automagically detect them.
313 * ---------------------------------------------------------------------
316 * indent-tabs-mode: t