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 1735 2004-12-07 14:33:27Z twisti $
39 #include "toolbox/logging.h"
40 #include "vm/global.h"
41 #include "vm/tables.h"
42 #include "vm/statistics.h"
45 /***************************************************************************
47 ***************************************************************************/
53 void log_init(char *fname)
57 logfile = fopen(fname, "w");
63 /*********************** Function: dolog ************************************
65 Writes logtext to the protocol file (if opened) or to stdout.
67 **************************************************************************/
69 void dolog(char *txt, ...)
71 char logtext[MAXLOGTEXT];
75 vsprintf(logtext, txt, ap);
79 fprintf(logfile, "%s\n",logtext);
83 fprintf(stdout,"LOG: %s\n",logtext);
89 /******************** Function: dolog_plain *******************************
91 Writes logtext to the protocol file (if opened) or to stdout.
93 **************************************************************************/
95 void dolog_plain(char *txt, ...)
97 char logtext[MAXLOGTEXT];
101 vsprintf(logtext, txt, ap);
105 fprintf(logfile, "%s", logtext);
109 fprintf(stdout,"%s", logtext);
115 /********************* Function: log_text ********************************/
117 void log_text(char *text)
123 /******************** Function: log_plain *******************************/
125 void log_plain(char *text)
127 dolog_plain("%s", text);
131 /****************** Function: get_logfile *******************************/
135 return (logfile) ? logfile : stdout;
139 /****************** Function: log_flush *********************************/
143 fflush(get_logfile());
147 /********************* Function: log_nl *********************************/
152 fflush(get_logfile());
156 /********************* Function: log_cputime ****************************/
162 char logtext[MAXLOGTEXT];
168 sprintf(logtext, "Total CPU usage: %d seconds and %d milliseconds",
174 /* log_message_method **********************************************************
176 outputs log text like this:
178 LOG: Loading class: java.lang.Object
180 *******************************************************************************/
182 void log_message_class(char *msg, classinfo *c)
184 char logtext[MAXLOGTEXT];
186 sprintf(logtext, msg);
187 utf_sprint_classname(logtext + strlen(logtext), c->name);
193 /* log_message_method **********************************************************
195 outputs log text like this:
197 LOG: Compiling: java.lang.Object.clone()Ljava.lang.Object;
199 *******************************************************************************/
201 void log_message_method(char *msg, methodinfo *m)
203 char logtext[MAXLOGTEXT];
205 sprintf(logtext, msg);
206 utf_sprint_classname(logtext + strlen(logtext), m->class->name);
207 strcpy(logtext + strlen(logtext), ".");
208 utf_sprint(logtext + strlen(logtext), m->name);
209 utf_sprint_classname(logtext + strlen(logtext), m->descriptor);
215 /************************** Function: error *******************************
217 Like dolog(), but terminates the program immediately.
219 **************************************************************************/
221 void error(char *txt, ...)
223 char logtext[MAXLOGTEXT];
227 vsprintf(logtext, txt, ap);
231 fprintf(logfile, "ERROR: %s\n", logtext);
234 fprintf(stderr, "ERROR: %s\n", logtext);
240 /************************ Function: panic (txt) ****************************
242 Like error(), takes the text to output as an argument
244 ***************************************************************************/
246 void panic(char *txt)
253 * These are local overrides for various environment variables in Emacs.
254 * Please do not remove this and leave it at the end of the file, where
255 * Emacs will automagically detect them.
256 * ---------------------------------------------------------------------
259 * indent-tabs-mode: t