diff --git a/src/engine/FileIO.c b/src/engine/FileIO.c index 2763345ed4..127cbd0c69 100644 --- a/src/engine/FileIO.c +++ b/src/engine/FileIO.c @@ -117,6 +117,9 @@ * new/improved account & transaction structures */ +/* This static indicates the debugging module that this .o belongs to. */ +static short module = MOD_IO; + /** GLOBALS *********************************************************/ /* the default currency is used when importin old-style @@ -365,7 +368,7 @@ readGroup (int fd, Account *aparent, int token) } XACC_FLIP_INT (numAcc); - INFO_2 ("readGroup(): expecting %d accounts \n", numAcc); + DEBUG ("readGroup(): expecting %d accounts \n", numAcc); /* read in the accounts */ for( i=0; iid; XACC_FLIP_INT (acc_id); @@ -1464,7 +1467,7 @@ writeAccount( int fd, Account *acc ) if( err != sizeof(int) ) return -1; - INFO_2 ("writeAccount(): will write %d trans\n", numUnwrittenTrans); + DEBUG ("writeAccount(): will write %d trans\n", numUnwrittenTrans); i=0; s = acc->splits[i]; while (s) { @@ -1595,7 +1598,7 @@ writeSplit ( int fd, Split *split ) if( -1 == err ) return err; damount = xaccSplitGetShareAmount (split); - INFO_2 ("writeSplit: amount=%f \n", damount); + DEBUG ("writeSplit: amount=%f \n", damount); XACC_FLIP_DOUBLE (damount); err = write( fd, &damount, sizeof(double) ); if( err != sizeof(double) ) @@ -1611,7 +1614,7 @@ writeSplit ( int fd, Split *split ) xfer_acc = split->acc; acc_id = -1; if (xfer_acc) acc_id = xfer_acc -> id; - INFO_2 ("writeSplit: credit %d \n", acc_id); + DEBUG ("writeSplit: credit %d \n", acc_id); XACC_FLIP_INT (acc_id); err = write( fd, &acc_id, sizeof(int) ); if( err != sizeof(int) ) diff --git a/src/engine/QIFIO.c b/src/engine/QIFIO.c index d72d0fb530..32c9cf3d94 100644 --- a/src/engine/QIFIO.c +++ b/src/engine/QIFIO.c @@ -54,6 +54,9 @@ static int error_code=0; /* error code, if error occurred */ +/* This static indicates the debugging module that this .o belongs to. */ +static short module = MOD_IO; + /*******************************************************/ int diff --git a/src/engine/util.c b/src/engine/util.c index 9da4cee581..feb4f14bc7 100644 --- a/src/engine/util.c +++ b/src/engine/util.c @@ -31,7 +31,13 @@ #include "util.h" /** GLOBALS *********************************************************/ -int loglevel = 1; +int loglevel[MODULE_MAX] = +{0, /* DUMMY */ + 4, /* ENGINE */ + 1, /* IO */ + 3, /* REGISTER */ + 2, /* GUI */ +}; /********************************************************************\ * DEBUGGING MEMORY ALLOCATION STUFF * diff --git a/src/engine/util.h b/src/engine/util.h index d5fcd4ec14..1b8e828261 100644 --- a/src/engine/util.h +++ b/src/engine/util.h @@ -31,37 +31,36 @@ #define BUFSIZE 1024 -extern int loglevel; - /** DEBUGGING MACROS ************************************************/ +/* The debuging macros enable the setting of trace messages */ +#include #include -#define PERR(x) { if (0 <=loglevel) { \ - fprintf (stderr, "Error: "); \ - fprintf (stderr, x); }} +#define MOD_ENGINE 1 +#define MOD_IO 2 +#define MOD_LEDGER 3 +#define MOD_GUI 4 +#define MODULE_MAX 5 -#define WARN(x) { if (1 <=loglevel) { \ - fprintf (stderr, "Warning: "); \ - fprintf (stderr, x); }} +extern int loglevel[MODULE_MAX]; -#define INFO(x) { if (2 <=loglevel) { \ - fprintf (stderr, "Info: "); \ - fprintf (stderr, x); }} +#define LERR (1 <= loglevel[module]) +#define LWARN (2 <= loglevel[module]) +#define LINFO (3 <= loglevel[module]) +#define LDEBUG (4 <= loglevel[module]) +#define LDETAIL (5 <= loglevel[module]) -#define INFO_2(x,y) { if (2 <=loglevel) { \ - fprintf (stderr, "Info: "); \ - fprintf (stderr, x, y); }} -#define DEBUG(x) { if (3 <=loglevel) { \ - fprintf (stderr, "Debug: "); \ - fprintf (stderr, x); }} - -#define ENTER(x) { if (3 <=loglevel) { \ - fprintf(stderr,"Entering: %s()\n", x); }} -#define LEAVE(x) { if (3 <=loglevel) { \ - fprintf(stderr,"Leaving: %s()\n", x); }} -#define DEBUGCMD(x) { if (3 <=loglevel) { x; }} +/* utility macros */ +#define PERR(x...) LG(LERR, "Error: "); LG(LERR, ##x); +#define PWARN(x...) LG(LWARN, "Waring: "); LG(LWARN, ##x); +#define PINFO(x...) LG(LINFO, "Info: "); LG(LINFO, ##x); +#define DEBUG(x...) LG(LDEBUG, "Debug: "); LG(LDEBUG, ##x); +#define ENTER(x...) LG(LDEBUG, "Enter: "); LG(LDEBUG, ##x); +#define LEAVE(x...) LG(LDEBUG, "Leave: "); LG(LDEBUG, ##x); +#define DETAIL(x...) LG(LDETAIL, "Detail: "); LG(LDETAIL, ##x); +#define DEBUGCMD(x) { if (INFO) { x; }} #include #define ERROR() fprintf(stderr,"%s: Line %d, error = %s\n", \