# HG changeset patch # User Dirk Olmes # Date 1279852748 -7200 # Node ID 254d5b89a6caa0856f3779e81a367b662498909d # Parent c82f5538733c83c7a95bad8b9b287d05f2d4e92a make sqlalchemy logging configurable through the --databaseLogging commandline parameter diff -r c82f5538733c -r 254d5b89a6ca Database.py --- 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 diff -r c82f5538733c -r 254d5b89a6ca util.py --- 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"):