diff --git a/libgnucash/engine/engine.i b/libgnucash/engine/engine.i index ec8dd3d158..34b49e93cc 100644 --- a/libgnucash/engine/engine.i +++ b/libgnucash/engine/engine.i @@ -24,6 +24,7 @@ #include #include #include "qof.h" +#include "qoflog.h" #include "Query.h" #include "gnc-budget.h" #include "gnc-commodity.h" @@ -83,6 +84,20 @@ engine-common.i */ %include "engine-common.i" %include "engine-deprecated.h" +#if defined(SWIGGUILE) +%ignore QofLogModule; +%typemap(in) QofLogModule { + $1 = (const char *)SWIG_scm2str($input); + } + +%typemap(freearg) QofLogModule { + SWIG_free((char*)$1); + } + +#endif + +%include "qoflog.h" + %inline %{ static const GncGUID * gncPriceGetGUID(GNCPrice *x) { return qof_instance_get_guid(QOF_INSTANCE(x)); } @@ -325,6 +340,13 @@ void qof_book_set_string_option(QofBook* book, const char* opt_name, const char* SET_ENUM("QOF-COMPARE-CONTAINS"); SET_ENUM("QOF-COMPARE-NCONTAINS"); + SET_ENUM("QOF-LOG-DEBUG"); + SET_ENUM("QOF-LOG-FATAL"); + SET_ENUM("QOF-LOG-ERROR"); + SET_ENUM("QOF-LOG-WARNING"); + SET_ENUM("QOF-LOG-MESSAGE"); + SET_ENUM("QOF-LOG-INFO"); + SET_ENUM("QOF-NUMERIC-MATCH-ANY"); SET_ENUM("QOF-NUMERIC-MATCH-CREDIT"); SET_ENUM("QOF-NUMERIC-MATCH-DEBIT"); diff --git a/libgnucash/engine/qoflog.h b/libgnucash/engine/qoflog.h index f7d6cbd350..345ad5f1a3 100644 --- a/libgnucash/engine/qoflog.h +++ b/libgnucash/engine/qoflog.h @@ -96,15 +96,15 @@ extern "C" #define QOF_MOD_ENGINE "qof.engine" -#define LOG_LEVEL_LIST(_) \ - _(QOF_LOG_FATAL, = G_LOG_LEVEL_ERROR) \ - _(QOF_LOG_ERROR, = G_LOG_LEVEL_CRITICAL) \ - _(QOF_LOG_WARNING, = G_LOG_LEVEL_WARNING) \ - _(QOF_LOG_MESSAGE, = G_LOG_LEVEL_MESSAGE) \ - _(QOF_LOG_INFO, = G_LOG_LEVEL_INFO) \ - _(QOF_LOG_DEBUG, = G_LOG_LEVEL_DEBUG) - -DEFINE_ENUM (QofLogLevel, LOG_LEVEL_LIST) +typedef enum +{ + QOF_LOG_FATAL = G_LOG_LEVEL_ERROR, + QOF_LOG_ERROR = G_LOG_LEVEL_CRITICAL, + QOF_LOG_WARNING = G_LOG_LEVEL_WARNING, + QOF_LOG_MESSAGE = G_LOG_LEVEL_MESSAGE, + QOF_LOG_INFO = G_LOG_LEVEL_INFO, + QOF_LOG_DEBUG = G_LOG_LEVEL_DEBUG +} QofLogLevel; const char* qof_log_level_to_string(QofLogLevel lvl); QofLogLevel qof_log_level_from_string(const char *str); diff --git a/libgnucash/scm/CMakeLists.txt b/libgnucash/scm/CMakeLists.txt index 731e44a332..5b3ce0e860 100644 --- a/libgnucash/scm/CMakeLists.txt +++ b/libgnucash/scm/CMakeLists.txt @@ -1,6 +1,6 @@ add_subdirectory(test) -set(GUILE_DEPENDS scm-core-utils scm-gnc-module) +set(GUILE_DEPENDS scm-core-utils scm-gnc-module gncmod-engine) gnc_add_scheme_targets(scm-scm diff --git a/libgnucash/scm/utilities.scm b/libgnucash/scm/utilities.scm index 509bb53762..4e3af3fdc6 100644 --- a/libgnucash/scm/utilities.scm +++ b/libgnucash/scm/utilities.scm @@ -27,6 +27,10 @@ (use-modules (gnucash core-utils)) +(eval-when (compile load eval expand) + (load-extension "libgncmod-engine" "scm_init_sw_engine_module")) +(use-modules (sw_engine)) + ;; Load the srfis (eventually, we should see where these are needed ;; and only have the use-modules statements in those files). (use-modules (srfi srfi-1)) @@ -62,8 +66,18 @@ (define (gnc:msg . items) (gnc-scm-log-msg (strify items))) -(define (gnc:debug . items) - (gnc-scm-log-debug (strify items))) +;; this definition of gnc:debug is different from others because we +;; want to check loglevel is debug *once* at gnc:debug definition +;; instead of every call to gnc:debug. if loglevel isn't debug then +;; gnc:debug becomes a NOOP. +(define gnc:debug + (cond + ((qof-log-check "gnc" QOF-LOG-DEBUG) + (display "debugging enabled\n") + (lambda items (gnc-scm-log-debug (strify items)))) + + (else + (lambda items #f)))) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; the following functions are initialized to log message to tracefile