From 5cc6eef4b9cd55e6b9f7dcc90c26a77996f3bc91 Mon Sep 17 00:00:00 2001 From: "Gonzalo A. Diethelm" Date: Thu, 4 Nov 1999 17:45:24 +0000 Subject: [PATCH] ChangeLogTag:Thu Nov 04 14:32:06 1999 Gonzalo A. Diethelm --- harbour/ChangeLog | 8 ++++++++ harbour/doc/tracing.txt | 18 ++++++++++++++---- harbour/source/common/hbtrace.c | 32 +++++++++++++++++++------------- 3 files changed, 41 insertions(+), 17 deletions(-) diff --git a/harbour/ChangeLog b/harbour/ChangeLog index 5ca99a1e8e..d3fd1fa311 100644 --- a/harbour/ChangeLog +++ b/harbour/ChangeLog @@ -1,3 +1,11 @@ +Thu Nov 04 14:32:06 1999 Gonzalo A. Diethelm + + * source/common/hbtrace.c: + * doc/tracing.txt: + Added the possibility to direct tracing output to a file by + specifying its name in the HB_TR_OUTPUT environment variable. The + default is stderr. + Thu Nov 04 13:49:23 1999 Gonzalo A. Diethelm * include/hbtrace.h: diff --git a/harbour/doc/tracing.txt b/harbour/doc/tracing.txt index ec99fdc852..ebc81385b2 100644 --- a/harbour/doc/tracing.txt +++ b/harbour/doc/tracing.txt @@ -20,7 +20,7 @@ The level specified for the HB_TRACE call affects harbour in two ways: compilation time and run time. -Compilation Time +COMPILATION TIME ================ At compilation time, the macro checks whether the preprocessor @@ -43,7 +43,7 @@ simply disappear, and there is no effect in the code performance thereafter. -Run Time +RUN TIME ======== At run time, the user can set the environment variable HB_TR_LEVEL to @@ -61,7 +61,7 @@ compiler and which have a level lower or equal to HB_TR_LEVEL will print its arguments on stderr. -Examples +EXAMPLES ======== HB_TR_LEVEL HB_TR_LEVEL Description @@ -99,7 +99,7 @@ the calls to the tracing function for the INFO level will be done anyway, so there will be a performance hit. -Usage +USAGE ===== When Harbour is compiled/run with some level of tracing and then used @@ -110,6 +110,16 @@ shell (such as bash) you can redirect stderr to a file like this: my_app 2>trace.txt +REDIRECTION +=========== + +The output generated while tracing goes to stderr by default. You can +control this at run-time by setting the environment variable +HB_TR_OUTPUT to the name of a file where you would like the tracing +output to be directed. If there is any problem opening the file for +writing, the output reverts to stderr. + + TRACING THE PREPROCESSOR AND COMPILER ===================================== diff --git a/harbour/source/common/hbtrace.c b/harbour/source/common/hbtrace.c index b81180b1c2..ef12198f7f 100644 --- a/harbour/source/common/hbtrace.c +++ b/harbour/source/common/hbtrace.c @@ -42,6 +42,7 @@ char * hb_tr_file_ = ""; int hb_tr_line_ = 0; int hb_tr_level_ = 0; +static FILE* hb_tr_fp_ = 0; static char* slevel[HB_TR_LAST] = { "HB_TR_ALWAYS", @@ -76,20 +77,20 @@ void hb_tr_trace( char * fmt, ... ) /* * Print file and line. */ - fprintf(stderr, "%s:%d: %s ", + fprintf(hb_tr_fp_, "%s:%d: %s ", hb_tr_file_ + i, hb_tr_line_, slevel[hb_tr_level_]); /* * Print the name and arguments for the function. */ va_start(ap, fmt); - vfprintf(stderr, fmt, ap); + vfprintf(hb_tr_fp_, fmt, ap); va_end(ap); /* * Print a new-line. */ - fprintf(stderr, "\n"); + fprintf(hb_tr_fp_, "\n"); /* * Reset file and line. @@ -104,23 +105,28 @@ int hb_tr_level(void) static int level = -1; int i; char* env; + char* out; - if (level != -1) - { + if (level != -1) { return level; } + hb_tr_fp_ = stderr; + out = getenv("HB_TR_OUTPUT"); + if (out != 0 && out[0] != '\0') { + hb_tr_fp_ = fopen(out, "w"); + if (hb_tr_fp_ == NULL) { + hb_tr_fp_ = stderr; + } + } + env = getenv("HB_TR_LEVEL"); - if (env == 0 || env[0] == '\0') - { + if (env == 0 || env[0] == '\0') { level = HB_TR_DEFAULT; } - else - { - for (i = 0; i < HB_TR_LAST; ++i) - { - if (strcmp(env, slevel[i]) == 0) - { + else { + for (i = 0; i < HB_TR_LAST; ++i) { + if (strcmp(env, slevel[i]) == 0) { level = i; break; }