1 /* toolbox/logging.c - contains logging functions
3 Copyright (C) 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003
4 Institut f. Computersprachen, TU Wien
5 R. Grafl, A. Krall, C. Kruegel, C. Oates, R. Obermaisser, M. Probst,
6 S. Ring, E. Steiner, C. Thalinger, D. Thuernbeck, P. Tomsich,
9 This file is part of CACAO.
11 This program is free software; you can redistribute it and/or
12 modify it under the terms of the GNU General Public License as
13 published by the Free Software Foundation; either version 2, or (at
14 your option) any later version.
16 This program is distributed in the hope that it will be useful, but
17 WITHOUT ANY WARRANTY; without even the implied warranty of
18 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19 General Public License for more details.
21 You should have received a copy of the GNU General Public License
22 along with this program; if not, write to the Free Software
23 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
26 Contact: cacao@complang.tuwien.ac.at
28 Authors: Reinhard Grafl
30 $Id: logging.c 1621 2004-11-30 13:06:55Z twisti $
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(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(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(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(char *text)
124 /******************** Function: log_plain *******************************/
126 void log_plain(char *text)
128 dolog_plain("%s", text);
132 /****************** Function: get_logfile *******************************/
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 ****************************/
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(char *msg, classinfo *c)
185 char logtext[MAXLOGTEXT];
187 sprintf(logtext, msg);
188 utf_sprint_classname(logtext + strlen(logtext), c->name);
194 /* log_message_method **********************************************************
196 outputs log text like this:
198 LOG: Compiling: java.lang.Object.clone()Ljava.lang.Object;
200 *******************************************************************************/
202 void log_message_method(char *msg, methodinfo *m)
204 char logtext[MAXLOGTEXT];
206 sprintf(logtext, msg);
207 utf_sprint_classname(logtext + strlen(logtext), m->class->name);
208 strcpy(logtext + strlen(logtext), ".");
209 utf_sprint(logtext + strlen(logtext), m->name);
210 utf_sprint_classname(logtext + strlen(logtext), m->descriptor);
216 /************************** Function: error *******************************
218 Like dolog(), but terminates the program immediately.
220 **************************************************************************/
222 void error(char *txt, ...)
224 char logtext[MAXLOGTEXT];
228 vsprintf(logtext, txt, ap);
232 fprintf(logfile, "ERROR: %s\n", logtext);
235 fprintf(stderr, "ERROR: %s\n", logtext);
241 /************************ Function: panic (txt) ****************************
243 Like error(), takes the text to output as an argument
245 ***************************************************************************/
247 void panic(char *txt)
254 * These are local overrides for various environment variables in Emacs.
255 * Please do not remove this and leave it at the end of the file, where
256 * Emacs will automagically detect them.
257 * ---------------------------------------------------------------------
260 * indent-tabs-mode: t