summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ChangeLog9
-rw-r--r--psycopg/config.h11
-rw-r--r--psycopg/psycopgmodule.c9
3 files changed, 28 insertions, 1 deletions
diff --git a/ChangeLog b/ChangeLog
index 79477e9..abdf993 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,12 @@
+2007-12-22 James Henstridge <james@jamesh.id.au>
+
+ * psycopg/config.h: only print debug messages if
+ psycopg_debug_enabled is true.
+
+ * psycopg/psycopgmodule.c (init_psycopg): set
+ psycopg_debug_enabled to true if the $PSYCOPG_DEBUG environment
+ variable is set.
+
2007-12-21 Federico Di Gregorio <fog@initd.org>
* Applied win32 patch from Jason Erickson.
diff --git a/psycopg/config.h b/psycopg/config.h
index be5e39d..eda2ea4 100644
--- a/psycopg/config.h
+++ b/psycopg/config.h
@@ -23,12 +23,17 @@
#define PSYCOPG_CONFIG_H 1
/* debug printf-like function */
+#ifdef PSYCOPG_DEBUG
+extern int psycopg_debug_enabled;
+#endif
+
#if defined( __GNUC__) && !defined(__APPLE__)
#ifdef PSYCOPG_DEBUG
#include <sys/types.h>
#include <unistd.h>
#define Dprintf(fmt, args...) \
- fprintf(stderr, "[%d] " fmt "\n", (int) getpid() , ## args)
+ if (!psycopg_debug_enabled) ; else \
+ fprintf(stderr, "[%d] " fmt "\n", (int) getpid() , ## args)
#else
#define Dprintf(fmt, args...)
#endif
@@ -38,6 +43,10 @@
static void Dprintf(const char *fmt, ...)
{
va_list ap;
+
+ if (!psycopg_debug_enabled)
+ return;
+ printf("[%d] ", (int) getpid());
va_start(ap, fmt);
vprintf(fmt, ap);
va_end(ap);
diff --git a/psycopg/psycopgmodule.c b/psycopg/psycopgmodule.c
index 2c4be8c..26cc500 100644
--- a/psycopg/psycopgmodule.c
+++ b/psycopg/psycopgmodule.c
@@ -63,6 +63,10 @@ PyObject *pyPsycopgTzFixedOffsetTimezone = NULL;
PyObject *psycoEncodings = NULL;
+#ifdef PSYCOPG_DEBUG
+int psycopg_debug_enabled = 0;
+#endif
+
/** connect module-level function **/
#define psyco_connect_doc \
"connect(dsn, ...) -- Create a new database connection.\n\n" \
@@ -693,6 +697,11 @@ init_psycopg(void)
PyObject *module, *dict;
PyObject *c_api_object;
+#ifdef PSYCOPG_DEBUG
+ if (getenv("PSYCOPG_DEBUG"))
+ psycopg_debug_enabled = 1;
+#endif
+
Dprintf("initpsycopg: initializing psycopg %s", PSYCOPG_VERSION);
/* initialize all the new types and then the module */