ChangeLogTag:Thu Nov 04 14:32:06 1999 Gonzalo A. Diethelm <Gonzalo.Diethelm@jda.cl>

This commit is contained in:
Gonzalo A. Diethelm
1999-11-04 17:45:24 +00:00
parent 997d822a9c
commit 5cc6eef4b9
3 changed files with 41 additions and 17 deletions

View File

@@ -1,3 +1,11 @@
Thu Nov 04 14:32:06 1999 Gonzalo A. Diethelm <Gonzalo.Diethelm@jda.cl>
* 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 <Gonzalo.Diethelm@jda.cl>
* include/hbtrace.h:

View File

@@ -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
=====================================

View File

@@ -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;
}