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 1245 2004-06-30 20:15:25Z twisti $
42 #include "toolbox/logging.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