diff --git a/src/engine/Account.c b/src/engine/Account.c index a107632fb4..1e2ab7c272 100644 --- a/src/engine/Account.c +++ b/src/engine/Account.c @@ -137,6 +137,9 @@ xaccCloneAccountSimple(const Account *from, GNCBook *book) { Account *ret; + if (!from || !book) return NULL; + ENTER (" "); + ret = g_new (Account, 1); g_return_val_if_fail (ret, NULL); @@ -157,6 +160,7 @@ xaccCloneAccountSimple(const Account *from, GNCBook *book) xaccAccountCommitEdit (ret); + LEAVE (" "); return ret; } @@ -166,6 +170,9 @@ xaccCloneAccount (const Account *from, GNCBook *book) time_t now; Account *ret; + if (!from || !book) return NULL; + ENTER (" "); + ret = g_new (Account, 1); g_return_val_if_fail (ret, NULL); @@ -191,6 +198,7 @@ xaccCloneAccount (const Account *from, GNCBook *book) xaccAccountCommitEdit (ret); + LEAVE (" "); return ret; } @@ -203,6 +211,7 @@ xaccAccountLookupTwin (Account *acc, GNCBook *book) int i, ncopies = 0; if (!acc || !book) return NULL; + ENTER (" "); v_ncopies = kvp_frame_get_slot_path (acc->kvp_data, "gemini", "ncopies"); if (!v_ncopies) return NULL; @@ -234,6 +243,7 @@ xaccAccountLookupTwin (Account *acc, GNCBook *book) return twin; } } + LEAVE (" "); return NULL; } diff --git a/src/engine/Group.c b/src/engine/Group.c index d26d5d7191..e69338efde 100644 --- a/src/engine/Group.c +++ b/src/engine/Group.c @@ -765,6 +765,7 @@ xaccGroupCopyGroup (AccountGroup *to, AccountGroup *from) if (!to || !from) return; if (!from->accounts || !to->book) return; + ENTER (" "); for (node = from->accounts; node; node=node->next) { Account *to_acc, *from_acc = node->data; @@ -793,6 +794,7 @@ xaccGroupCopyGroup (AccountGroup *to, AccountGroup *from) xaccAccountGroupBeginEdit (to_acc->children); } } + LEAVE (" "); } /********************************************************************\ diff --git a/src/engine/Group.h b/src/engine/Group.h index 325f775fcf..6ee26b10ac 100644 --- a/src/engine/Group.h +++ b/src/engine/Group.h @@ -180,7 +180,7 @@ AccountGroup * xaccAccountGetRoot (Account *account); Account * xaccGroupGetParentAccount (AccountGroup *group); /* The xaccGroupMapAccounts() routine will traverse the account - group, returning a list of accounts. If teh callback + group, returning a list of accounts. If the callback returns null for a given item, it won't show up in the result list. You should free the returned list when you are done with it. diff --git a/src/engine/Transaction.c b/src/engine/Transaction.c index f119e3369d..a911b36034 100644 --- a/src/engine/Transaction.c +++ b/src/engine/Transaction.c @@ -2363,7 +2363,7 @@ xaccTransSetDateInternal(Transaction *trans, int which, time_t secs, if(!trans) return; check_open(trans); - PINFO ("addr=%p set %d date to %lu %li %s \n", + PINFO ("addr=%p set %d date to %lu %li %s", trans, which, secs, nsecs, ctime (&secs)); dadate = ((which == TDATE_POSTED) diff --git a/src/engine/gnc-engine-util.c b/src/engine/gnc-engine-util.c index e1c2236a9d..5e4abe32d5 100644 --- a/src/engine/gnc-engine-util.c +++ b/src/engine/gnc-engine-util.c @@ -65,6 +65,7 @@ static gncLogLevel loglevel[MOD_LAST + 1] = GNC_LOG_DEBUG, /* SX */ }; +static FILE *fout = NULL; /* Set the logging level of the given module. */ void @@ -86,6 +87,12 @@ gnc_set_log_level_global(gncLogLevel level) loglevel[module] = level; } +void +gnc_set_logfile (FILE *outfile) +{ + fout = outfile; +} + /* prettify() cleans up subroutine names. AIX/xlC has the habit of * printing signatures not names; clean this up. On other operating * systems, truncate name to 30 chars. Note this routine is not thread @@ -138,17 +145,19 @@ gnc_log (gncModuleType module, gncLogLevel log_level, const char *prefix, if (!gnc_should_log (module, log_level)) return; - fprintf (stderr, "%s: %s: ", + if (!fout) fout = stderr; + + fprintf (fout, "%s: %s: ", prefix ? prefix : "(null)", prettify (function_name)); va_start (ap, format); - vfprintf (stderr, format, ap); + vfprintf (fout, format, ap); va_end (ap); - fprintf (stderr, "\n"); + fprintf (fout, "\n"); } @@ -173,16 +182,16 @@ gnc_start_clock (int clockno, gncModuleType module, gncLogLevel log_level, if ((0>clockno) || (NUM_CLOCKS <= clockno)) return; gettimeofday (&gnc_clock[clockno], &tz); - fprintf (stderr, "Clock %d Start: %s: ", + fprintf (fout, "Clock %d Start: %s: ", clockno, prettify (function_name)); va_start (ap, format); - vfprintf (stderr, format, ap); + vfprintf (fout, format, ap); va_end (ap); - fprintf (stderr, "\n"); + fprintf (fout, "\n"); } void @@ -205,16 +214,16 @@ gnc_report_clock (int clockno, gncModuleType module, gncLogLevel log_level, now.tv_sec -= gnc_clock[clockno].tv_sec; now.tv_usec -= gnc_clock[clockno].tv_usec; - fprintf (stderr, "Clock %d Elapsed: %ld.%06ld %s: ", + fprintf (fout, "Clock %d Elapsed: %ld.%06ld %s: ", clockno, now.tv_sec, now.tv_usec, prettify (function_name)); va_start (ap, format); - vfprintf (stderr, format, ap); + vfprintf (fout, format, ap); va_end (ap); - fprintf (stderr, "\n"); + fprintf (fout, "\n"); } /********************************************************************\ diff --git a/src/engine/gnc-engine-util.h b/src/engine/gnc-engine-util.h index 51880de666..7ae0fb5d85 100644 --- a/src/engine/gnc-engine-util.h +++ b/src/engine/gnc-engine-util.h @@ -79,6 +79,11 @@ typedef enum * the glib.h g_error(), etc functions. That way, we would have * unified logging mechanism, instead of having some messages * work one way, and other a different way ... + * + * FIXME: the if test should not be a subroutine call, it should + * not use that many CPU cycles. These logging functions are supposed + * to be lightweight. Who changed this ??? Why ??? + * */ gboolean gnc_should_log (gncModuleType module, gncLogLevel log_level); void gnc_log (gncModuleType module, gncLogLevel log_level, @@ -171,6 +176,8 @@ void gnc_set_log_level(gncModuleType module, gncLogLevel level); /* Set the logging level for all modules. */ void gnc_set_log_level_global(gncLogLevel level); +/* Pipe log output to pipe or file */ +void gnc_set_logfile (FILE *outfile); /** Macros *****************************************************/ #define EPS (1.0e-6) diff --git a/src/engine/test/test-period.c b/src/engine/test/test-period.c index 0afa95209d..359489697d 100644 --- a/src/engine/test/test-period.c +++ b/src/engine/test/test-period.c @@ -14,6 +14,7 @@ #include "Period.h" #include "gnc-book.h" #include "gnc-book-p.h" +#include "gnc-engine-util.h" #include "gnc-module.h" #include "test-stuff.h" #include "test-engine-stuff.h" @@ -107,6 +108,9 @@ run_test (void) tsmiddle = tsfirst; tsmiddle.tv_sec = (tsfirst.tv_sec + tslast.tv_sec)/2; + // stdout is broken with guile for some reason + // gnc_set_logfile (stdout); + // gnc_set_log_level_global (GNC_LOG_INFO); closedbook = gnc_book_close_period (openbook, tsmiddle, NULL, "this is opening balance dude");