1 /* 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 $Id: logging.c 1925 2005-02-10 10:46:33Z twisti $
39 #include "mm/memory.h"
40 #include "toolbox/logging.h"
41 #include "vm/global.h"
42 #include "vm/tables.h"
43 #include "vm/statistics.h"
46 /***************************************************************************
48 ***************************************************************************/
54 void log_init(const char *fname)
58 logfile = fopen(fname, "w");
64 /*********************** Function: dolog ************************************
66 Writes logtext to the protocol file (if opened) or to stdout.
68 **************************************************************************/
70 void dolog(const char *txt, ...)
72 char logtext[MAXLOGTEXT];
76 vsprintf(logtext, txt, ap);
80 fprintf(logfile, "%s\n",logtext);
84 fprintf(stdout,"LOG: %s\n",logtext);
90 /******************** Function: dolog_plain *******************************
92 Writes logtext to the protocol file (if opened) or to stdout.
94 **************************************************************************/
96 void dolog_plain(const char *txt, ...)
98 char logtext[MAXLOGTEXT];
102 vsprintf(logtext, txt, ap);
106 fprintf(logfile, "%s", logtext);
110 fprintf(stdout,"%s", logtext);
116 /********************* Function: log_text ********************************/
118 void log_text(const char *text)
124 /******************** Function: log_plain *******************************/
126 void log_plain(const char *text)
128 dolog_plain("%s", text);
132 /****************** Function: get_logfile *******************************/
134 FILE *get_logfile(void)
136 return (logfile) ? logfile : stdout;
140 /****************** Function: log_flush *********************************/
144 fflush(get_logfile());
148 /********************* Function: log_nl *********************************/
153 fflush(get_logfile());
157 /********************* Function: log_cputime ****************************/
159 void log_cputime(void)
163 char logtext[MAXLOGTEXT];
169 sprintf(logtext, "Total CPU usage: %d seconds and %d milliseconds",
175 /* log_message_method **********************************************************
177 outputs log text like this:
179 LOG: Loading class: java.lang.Object
181 *******************************************************************************/
183 void log_message_class(const char *msg, classinfo *c)
188 len = strlen(msg) + utf_strlen(c->name) + 1;
190 buf = MNEW(char, len);
193 utf_sprint_classname(buf + strlen(buf), c->name);
197 MFREE(buf, char, len);
201 /* log_message_method **********************************************************
203 outputs log text like this:
205 LOG: Compiling: java.lang.Object.clone()Ljava.lang.Object;
207 *******************************************************************************/
209 void log_message_method(const char *msg, methodinfo *m)
214 len = strlen(msg) + utf_strlen(m->class->name) + 1 +
215 utf_strlen(m->name) + utf_strlen(m->descriptor) + 1;
217 buf = MNEW(char, len);
220 utf_sprint_classname(buf + strlen(buf), m->class->name);
221 strcpy(buf + strlen(buf), ".");
222 utf_sprint(buf + strlen(buf), m->name);
223 utf_sprint_classname(buf + strlen(buf), m->descriptor);
227 MFREE(buf, char, len);
231 /* error ***********************************************************************
233 Like dolog(), but terminates the program immediately.
235 *******************************************************************************/
237 void error(const char *txt, ...)
239 char logtext[MAXLOGTEXT];
243 vsprintf(logtext, txt, ap);
247 fprintf(logfile, "ERROR: %s\n", logtext);
250 fprintf(stderr, "ERROR: %s\n", logtext);
256 /* panic ***********************************************************************
258 Like error(), takes the text to output as an argument.
260 *******************************************************************************/
262 void panic(const char *txt)
268 /* log_utf *********************************************************************
272 *******************************************************************************/
276 char buf[MAXLOGTEXT];
282 /* log_plain_utf ***************************************************************
284 Log utf symbol (without printing "LOG: " and newline).
286 *******************************************************************************/
288 void log_plain_utf(utf *u)
290 char buf[MAXLOGTEXT];
292 dolog_plain("%s", buf);
297 * These are local overrides for various environment variables in Emacs.
298 * Please do not remove this and leave it at the end of the file, where
299 * Emacs will automagically detect them.
300 * ---------------------------------------------------------------------
303 * indent-tabs-mode: t