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.
This commit is contained in:
James Henstridge 2007-12-22 13:03:41 +00:00
parent f3e74d2c48
commit 5fe08ae83e
3 changed files with 28 additions and 1 deletions

View File

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

View File

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

View File

@ -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 */