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 2133 2005-03-30 09:49:41Z twisti $
42 #include "mm/memory.h"
43 #include "toolbox/logging.h"
44 #include "vm/global.h"
45 #include "vm/tables.h"
46 #include "vm/statistics.h"
49 /***************************************************************************
51 ***************************************************************************/
56 void log_init(const char *fname)
60 logfile = fopen(fname, "w");
66 /*********************** Function: dolog ************************************
68 Writes logtext to the protocol file (if opened) or to stdout.
70 **************************************************************************/
72 void dolog(const char *txt, ...)
74 char logtext[MAXLOGTEXT];
78 vsprintf(logtext, txt, ap);
82 fprintf(logfile, "%s\n",logtext);
86 fprintf(stdout,"LOG: %s\n",logtext);
92 /******************** Function: dolog_plain *******************************
94 Writes logtext to the protocol file (if opened) or to stdout.
96 **************************************************************************/
98 void dolog_plain(const char *txt, ...)
100 char logtext[MAXLOGTEXT];
104 vsprintf(logtext, txt, ap);
108 fprintf(logfile, "%s", logtext);
112 fprintf(stdout,"%s", logtext);
118 /********************* Function: log_text ********************************/
120 void log_text(const char *text)
126 /******************** Function: log_plain *******************************/
128 void log_plain(const char *text)
130 dolog_plain("%s", text);
134 /****************** Function: get_logfile *******************************/
136 FILE *get_logfile(void)
138 return (logfile) ? logfile : stdout;
142 /****************** Function: log_flush *********************************/
146 fflush(get_logfile());
150 /********************* Function: log_nl *********************************/
155 fflush(get_logfile());
159 /* log_cputime *****************************************************************
163 *******************************************************************************/
165 #if defined(STATISTICS)
166 void log_cputime(void)
170 char logtext[MAXLOGTEXT];
176 sprintf(logtext, "Total CPU usage: %d seconds and %d milliseconds",
183 /* log_message_method **********************************************************
185 outputs log text like this:
187 LOG: Loading class: java/lang/Object
189 *******************************************************************************/
191 void log_message_class(const char *msg, classinfo *c)
196 len = strlen(msg) + utf_strlen(c->name) + strlen("0");
198 buf = MNEW(char, len);
201 utf_strcat(buf, c->name);
205 MFREE(buf, char, len);
209 /* log_message_method **********************************************************
211 outputs log text like this:
213 LOG: Compiling: java.lang.Object.clone()Ljava/lang/Object;
215 *******************************************************************************/
217 void log_message_method(const char *msg, methodinfo *m)
222 len = strlen(msg) + utf_strlen(m->class->name) + strlen(".") +
223 utf_strlen(m->name) + utf_strlen(m->descriptor) + strlen("0");
225 buf = MNEW(char, len);
228 utf_strcat_classname(buf, m->class->name);
230 utf_strcat(buf, m->name);
231 utf_strcat(buf, m->descriptor);
235 MFREE(buf, char, len);
239 /* error ***********************************************************************
241 Like dolog(), but terminates the program immediately.
243 *******************************************************************************/
245 void error(const char *txt, ...)
247 char logtext[MAXLOGTEXT];
251 vsprintf(logtext, txt, ap);
255 fprintf(logfile, "ERROR: %s\n", logtext);
258 fprintf(stderr, "ERROR: %s\n", logtext);
264 /* panic ***********************************************************************
266 Like error(), takes the text to output as an argument.
268 *******************************************************************************/
270 void panic(const char *txt)
276 /* log_utf *********************************************************************
280 *******************************************************************************/
284 char buf[MAXLOGTEXT];
290 /* log_plain_utf ***************************************************************
292 Log utf symbol (without printing "LOG: " and newline).
294 *******************************************************************************/
296 void log_plain_utf(utf *u)
298 char buf[MAXLOGTEXT];
300 dolog_plain("%s", buf);
305 * These are local overrides for various environment variables in Emacs.
306 * Please do not remove this and leave it at the end of the file, where
307 * Emacs will automagically detect them.
308 * ---------------------------------------------------------------------
311 * indent-tabs-mode: t