# HG changeset patch # User Dirk Olmes # Date 1272414180 -7200 # Node ID 591ecc2a99bdc11e615f617bac75967443512518 # Parent 9ede118b93efa93344104a4362b8bc55c2b13a86 move logging configuration to the util module, configure logging for sqlalchemy diff -r 9ede118b93ef -r 591ecc2a99bd database.py --- a/database.py Wed Apr 28 02:09:48 2010 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,22 +0,0 @@ - -from ConfigParser import ConfigParser -import Mapping -import socket -from sqlalchemy import create_engine -from sqlalchemy.orm import sessionmaker - -def createSession(): - databaseUrl = loadDatabaseUrl() - engine = create_engine(databaseUrl,echo=True) - Mapping.createMapping(engine) - SessionMaker = sessionmaker(bind = engine) - session = SessionMaker() - return session - -def loadDatabaseUrl(): - hostname = socket.gethostname() - filename = "database-%s.ini" % hostname - - parser = ConfigParser(); - parser.read(filename) - return parser.get("database", "url") diff -r 9ede118b93ef -r 591ecc2a99bd feedupdate-main.py --- a/feedupdate-main.py Wed Apr 28 02:09:48 2010 +0200 +++ b/feedupdate-main.py Wed Apr 28 02:23:00 2010 +0200 @@ -1,6 +1,6 @@ #!/usr/bin/env python -from database import createSession +from util import configureLogging, createSession from Feed import Feed from FeedUpdater import updateAllFeeds import logging @@ -21,6 +21,7 @@ print entry.title if __name__ == "__main__": + configureLogging() session = createSession() createFeed(session) diff -r 9ede118b93ef -r 591ecc2a99bd util.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/util.py Wed Apr 28 02:23:00 2010 +0200 @@ -0,0 +1,31 @@ + +from ConfigParser import ConfigParser +import logging +import Mapping +import socket +from sqlalchemy import create_engine +from sqlalchemy.orm import sessionmaker + +logger = logging.getLogger("database") + +def configureLogging(): + logging.basicConfig(level=logging.DEBUG) + logging.getLogger("sqlalchemy").setLevel(logging.INFO) + logging.getLogger("sqlalchemy.orm").setLevel(logging.WARN) + +def createSession(): + databaseUrl = loadDatabaseUrl() + engine = create_engine(databaseUrl,echo=True) + Mapping.createMapping(engine) + SessionMaker = sessionmaker(bind = engine) + session = SessionMaker() + return session + +def loadDatabaseUrl(): + hostname = socket.gethostname() + filename = "database-%s.ini" % hostname + logger.debug("loading database configuration from " + filename) + + parser = ConfigParser(); + parser.read(filename) + return parser.get("database", "url")