changeset 57:254d5b89a6ca

make sqlalchemy logging configurable through the --databaseLogging commandline parameter
author Dirk Olmes <dirk@xanthippe.ping.de>
date Fri, 23 Jul 2010 04:39:08 +0200
parents c82f5538733c
children dcee24702dd7
files Database.py util.py
diffstat 2 files changed, 17 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/Database.py	Fri Jul 23 04:06:10 2010 +0200
+++ b/Database.py	Fri Jul 23 04:39:08 2010 +0200
@@ -3,6 +3,7 @@
 import sqlalchemy
 import sqlalchemy.orm
 import sys
+import util
 
 # Keep the connection to the database only once. The feed updater and the GUI app will
 # operate on a single engine/session but this comes in handy for interactive use
@@ -25,7 +26,8 @@
 def initEngine(databaseUrl):
     global engine
     if engine is None:
-        engine = sqlalchemy.create_engine(databaseUrl, echo=True)
+        verbose = util.databaseLoggingEnabled()
+        engine = sqlalchemy.create_engine(databaseUrl, echo=verbose)
 
 def initSessionMaker():
     global SessionMaker
--- a/util.py	Fri Jul 23 04:06:10 2010 +0200
+++ b/util.py	Fri Jul 23 04:39:08 2010 +0200
@@ -2,12 +2,25 @@
 from datetime import datetime, timedelta
 from Feed import Feed
 import logging
+import sys
 
 logger = logging.getLogger("database")
 
+def databaseLoggingEnabled():
+    loggingEnabled = False
+    for arg in sys.argv:
+        if arg == "--databaseLogging":
+            loggingEnabled = True
+    return loggingEnabled
+
 def configureLogging():
     logging.basicConfig(level=logging.DEBUG)
-    logging.getLogger("sqlalchemy").setLevel(logging.INFO)
+    
+    sqlalchemyLogLevel = logging.ERROR
+    if databaseLoggingEnabled():
+        sqlalchemyLogLevel = logging.INFO
+    logging.getLogger("sqlalchemy").setLevel(sqlalchemyLogLevel)
+    
     logging.getLogger("sqlalchemy.orm").setLevel(logging.WARN)
 
 def loadFeeds(session=None, filename="feeds.txt"):