/* src/toolbox/logging.c - contains logging functions
- Copyright (C) 1996-2005 R. Grafl, A. Krall, C. Kruegel, C. Oates,
- R. Obermaisser, M. Platter, M. Probst, S. Ring, E. Steiner,
- C. Thalinger, D. Thuernbeck, P. Tomsich, C. Ullrich, J. Wenninger,
- Institut f. Computersprachen - TU Wien
+ Copyright (C) 1996-2005, 2006, 2007 R. Grafl, A. Krall, C. Kruegel,
+ C. Oates, R. Obermaisser, M. Platter, M. Probst, S. Ring,
+ E. Steiner, C. Thalinger, D. Thuernbeck, P. Tomsich, C. Ullrich,
+ J. Wenninger, Institut f. Computersprachen - TU Wien
This file is part of CACAO.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
- Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
- 02111-1307, USA.
-
- Contact: cacao@complang.tuwien.ac.at
-
- Authors: Reinhard Grafl
-
- Changes: Christian Thalinger
-
- $Id: logging.c 2508 2005-05-23 08:50:25Z twisti $
+ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ 02110-1301, USA.
*/
+#include "config.h"
+
#include <stdio.h>
-#include <stdarg.h>
#include <stdlib.h>
#include <string.h>
-#include "config.h"
+#include "vm/types.h"
+
#include "mm/memory.h"
#include "toolbox/logging.h"
#include "toolbox/util.h"
#include "vm/global.h"
-#include "vm/tables.h"
-#include "vm/statistics.h"
-#if defined(USE_THREADS)
-# if defined(NATIVE_THREADS)
-# include "threads/native/threads.h"
-# endif
+#if defined(ENABLE_STATISTICS)
+# include "vmcore/statistics.h"
#endif
}
-/* dolog ***********************************************************************
+/* log_start *******************************************************************
- Writes logtext to the protocol file (if opened) or to stdout.
+ Writes the preleading LOG: text to the protocol file (if opened) or
+ to stdout.
*******************************************************************************/
-void dolog(const char *text, ...)
-{
- va_list ap;
+/* ATTENTION: Don't include threads-common.h, because we can't
+ bootstrap this file in that case (missing java_lang_Thread.h).
+ Instead we declare threads_get_current_threadobject differently: */
- if (logfile) {
-#if defined(USE_THREADS) && defined(NATIVE_THREADS)
- fprintf(logfile, "[%p] ", (void *) THREADOBJECT);
-#endif
+/* #if defined(ENABLE_THREADS) */
+/* # include "threads/threads-common.h" */
+/* #endif */
- va_start(ap, text);
- vfprintf(logfile, text, ap);
- va_end(ap);
+extern ptrint threads_get_current_tid(void);
- fflush(logfile);
- } else {
-#if defined(USE_THREADS) && defined(NATIVE_THREADS)
- fprintf(stdout, "LOG: [%p] ", (void *) THREADOBJECT);
+void log_start(void)
+{
+#if defined(ENABLE_THREADS)
+ ptrint tid;
+
+ tid = threads_get_current_tid();
+#endif
+
+ if (logfile) {
+#if defined(ENABLE_THREADS)
+# if SIZEOF_VOID_P == 8
+ fprintf(logfile, "[0x%016lx] ", tid );
+# else
+ fprintf(logfile, "[0x%08x] ", tid);
+# endif
+#endif
+ }
+ else {
+#if defined(ENABLE_THREADS)
+# if SIZEOF_VOID_P == 8
+ fprintf(stdout, "LOG: [0x%016lx] ", tid);
+# else
+ fprintf(stdout, "LOG: [0x%08x] ", tid);
+# endif
#else
fputs("LOG: ", stdout);
#endif
-
- va_start(ap, text);
- vfprintf(stdout, text, ap);
- va_end(ap);
-
- fprintf(stdout, "\n");
-
- fflush(stdout);
}
}
-/******************** Function: dolog_plain *******************************
+/* log_vprint ******************************************************************
-Writes logtext to the protocol file (if opened) or to stdout.
+ Writes logtext to the protocol file (if opened) or to stdout.
-**************************************************************************/
+*******************************************************************************/
-void dolog_plain(const char *txt, ...)
+void log_vprint(const char *text, va_list ap)
{
- char logtext[MAXLOGTEXT];
- va_list ap;
-
- va_start(ap, txt);
- vsprintf(logtext, txt, ap);
- va_end(ap);
-
- if (logfile) {
- fprintf(logfile, "%s", logtext);
- fflush(logfile);
-
- } else {
- fprintf(stdout,"%s", logtext);
- fflush(stdout);
- }
+ if (logfile)
+ vfprintf(logfile, text, ap);
+ else
+ vfprintf(stdout, text, ap);
}
-/********************* Function: log_text ********************************/
-
-void log_text(const char *text)
-{
- dolog("%s", text);
-}
+/* log_print *******************************************************************
+ Writes logtext to the protocol file (if opened) or to stdout.
-/******************** Function: log_plain *******************************/
+*******************************************************************************/
-void log_plain(const char *text)
+void log_print(const char *text, ...)
{
- dolog_plain("%s", text);
+ va_list ap;
+
+ va_start(ap, text);
+ log_vprint(text, ap);
+ va_end(ap);
}
-/****************** Function: get_logfile *******************************/
+/* log_println *****************************************************************
-FILE *get_logfile(void)
-{
- return (logfile) ? logfile : stdout;
-}
+ Writes logtext to the protocol file (if opened) or to stdout with a
+ trailing newline.
+*******************************************************************************/
-/****************** Function: log_flush *********************************/
-
-void log_flush(void)
+void log_println(const char *text, ...)
{
- fflush(get_logfile());
-}
+ va_list ap;
+ log_start();
-/********************* Function: log_nl *********************************/
+ va_start(ap, text);
+ log_vprint(text, ap);
+ va_end(ap);
-void log_nl(void)
-{
- log_plain("\n");
- fflush(get_logfile());
+ log_finish();
}
-/* log_cputime *****************************************************************
+/* log_finish ******************************************************************
- XXX
+ Finishes a logtext line with trailing newline and a fflush.
*******************************************************************************/
-#if defined(STATISTICS)
-void log_cputime(void)
+void log_finish(void)
{
- s8 t;
- int sec, usec;
- char logtext[MAXLOGTEXT];
-
- t = getcputime();
- sec = t / 1000000;
- usec = t % 1000000;
-
- sprintf(logtext, "Total CPU usage: %d seconds and %d milliseconds",
- sec, usec / 1000);
- log_text(logtext);
+ if (logfile) {
+ fputs("\n", logfile);
+ fflush(logfile);
+ }
+ else {
+ fputs("\n", stdout);
+ fflush(stdout);
+ }
}
-#endif
/* log_message_utf *************************************************************
char *buf;
s4 len;
- len = strlen(msg) + utf_strlen(u) + strlen("0");
+ len = strlen(msg) + utf_bytes(u) + strlen("0");
buf = MNEW(char, len);
strcpy(buf, msg);
- utf_strcat(buf, u);
+ utf_cat(buf, u);
log_text(buf);
s4 len;
len =
- strlen(msg1) + utf_strlen(c1->name) +
- strlen(msg2) + utf_strlen(c2->name) + strlen("0");
+ strlen(msg1) + utf_bytes(c1->name) +
+ strlen(msg2) + utf_bytes(c2->name) + strlen("0");
buf = MNEW(char, len);
strcpy(buf, msg1);
- utf_strcat(buf, c1->name);
+ utf_cat_classname(buf, c1->name);
strcat(buf, msg2);
- utf_strcat(buf, c2->name);
+ utf_cat_classname(buf, c2->name);
log_text(buf);
char *buf;
s4 len;
- len = strlen(msg) + utf_strlen(m->class->name) + strlen(".") +
- utf_strlen(m->name) + utf_strlen(m->descriptor) + strlen("0");
+ len = strlen(msg) + utf_bytes(m->class->name) + strlen(".") +
+ utf_bytes(m->name) + utf_bytes(m->descriptor) + strlen("0");
buf = MNEW(char, len);
strcpy(buf, msg);
- utf_strcat_classname(buf, m->class->name);
+ utf_cat_classname(buf, m->class->name);
strcat(buf, ".");
- utf_strcat(buf, m->name);
- utf_strcat(buf, m->descriptor);
+ utf_cat(buf, m->name);
+ utf_cat(buf, m->descriptor);
log_text(buf);
}
-/* log_utf *********************************************************************
-
- Log utf symbol.
-
-*******************************************************************************/
-
-void log_utf(utf *u)
-{
- char buf[MAXLOGTEXT];
- utf_sprint(buf, u);
- dolog("%s", buf);
-}
-
-
-/* log_plain_utf ***************************************************************
-
- Log utf symbol (without printing "LOG: " and newline).
-
-*******************************************************************************/
-
-void log_plain_utf(utf *u)
-{
- char buf[MAXLOGTEXT];
- utf_sprint(buf, u);
- dolog_plain("%s", buf);
-}
-
-
/*
* These are local overrides for various environment variables in Emacs.
* Please do not remove this and leave it at the end of the file, where
* c-basic-offset: 4
* tab-width: 4
* End:
+ * vim:noexpandtab:sw=4:ts=4:
*/