Skip to content

Commit

Permalink
- Add logging configuration to all paster templates.
Browse files Browse the repository at this point in the history
- ``pyramid_alchemy``, ``pyramid_routesalchemy``, and ``pylons_sqla`` paster
  templates now use idiomatic SQLAlchemy configuration in their respective
  ``.ini`` files and Python code.
  • Loading branch information
mcdonc committed Nov 21, 2010
1 parent 1242389 commit 957f614
Show file tree
Hide file tree
Showing 16 changed files with 294 additions and 37 deletions.
9 changes: 9 additions & 0 deletions CHANGES.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,15 @@
Next release
============

Features
--------

- Add logging configuration to all paster templates.

- ``pyramid_alchemy``, ``pyramid_routesalchemy``, and ``pylons_sqla`` paster
templates now use idiomatic SQLAlchemy configuration in their respective
``.ini`` files and Python code.

Bug Fixes
---------

Expand Down
26 changes: 26 additions & 0 deletions docs/narr/MyProject/development.ini
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,29 @@ pipeline =
use = egg:Paste#http
host = 0.0.0.0
port = 6543

# Begin logging configuration

[loggers]
keys = root

[handlers]
keys = console

[formatters]
keys = generic

[logger_root]
level = INFO
handlers = console

[handler_console]
class = StreamHandler
args = (sys.stderr,)
level = NOTSET
formatter = generic

[formatter_generic]
format = %(asctime)s %(levelname)-5.5s [%(name)s][%(threadName)s] %(message)s

# End logging configuration
8 changes: 3 additions & 5 deletions pyramid/paster_templates/alchemy/+package+/__init__.py_tmpl
Original file line number Diff line number Diff line change
@@ -1,16 +1,14 @@
from pyramid.configuration import Configurator
from pyramid.settings import asbool
from sqlalchemy import engine_from_config

from {{package}}.models import appmaker

def main(global_config, **settings):
""" This function returns a WSGI application.
"""
db_string = settings.get('db_string')
if db_string is None:
raise ValueError("No 'db_string' value in application configuration.")
db_echo = settings.get('db_echo', 'false')
get_root = appmaker(db_string, asbool(db_echo))
engine = engine_from_config(settings, 'sqlalchemy.')
get_root = appmaker(engine)
config = Configurator(settings=settings, root_factory=get_root)
config.add_static_view('static', '{{package}}:static')
config.add_view('{{package}}.views.view_root',
Expand Down
7 changes: 3 additions & 4 deletions pyramid/paster_templates/alchemy/+package+/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,7 @@ def populate():
session.flush()
transaction.commit()

def initialize_sql(db_string, db_echo=False):
engine = create_engine(db_string, echo=db_echo)
def initialize_sql(engine):
DBSession.configure(bind=engine)
Base.metadata.bind = engine
Base.metadata.create_all(engine)
Expand All @@ -83,6 +82,6 @@ def initialize_sql(db_string, db_echo=False):
except IntegrityError:
pass

def appmaker(db_string, db_echo=False):
initialize_sql(db_string, db_echo)
def appmaker(engine):
initialize_sql(engine)
return default_get_root
37 changes: 35 additions & 2 deletions pyramid/paster_templates/alchemy/development.ini_tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@ debug_authorization = false
debug_notfound = false
debug_templates = true
default_locale_name = en
db_string = sqlite:///%(here)s/{{package}}.db
db_echo = false
sqlalchemy.url = sqlite:///%(here)s/{{project}}.db

[pipeline:main]
pipeline =
Expand All @@ -18,3 +17,37 @@ pipeline =
use = egg:Paste#http
host = 0.0.0.0
port = 6543

# Begin logging configuration

[loggers]
keys = root, sqlalchemy

[handlers]
keys = console

[formatters]
keys = generic

[logger_root]
level = INFO
handlers = console

[logger_sqlalchemy]
level = INFO
handlers =
qualname = sqlalchemy.engine
# "level = INFO" logs SQL queries.
# "level = DEBUG" logs SQL queries and results.
# "level = WARN" logs neither. (Recommended for production systems.)

[handler_console]
class = StreamHandler
args = (sys.stderr,)
level = NOTSET
formatter = generic

[formatter_generic]
format = %(asctime)s %(levelname)-5.5s [%(name)s][%(threadName)s] %(message)s

# End logging configuration
31 changes: 29 additions & 2 deletions pyramid/paster_templates/pylons_basic/development.ini_tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,37 @@ session.key = {{project}}
session.secret = {{random_string}}

[pipeline:main]
pipeline = egg:WebError#evalerror
{{project}}
pipeline =
egg:WebError#evalerror
{{project}}

[server:main]
use = egg:Paste#http
host = 0.0.0.0
port = 6543

# Begin logging configuration

[loggers]
keys = root

[handlers]
keys = console

[formatters]
keys = generic

[logger_root]
level = INFO
handlers = console

[handler_console]
class = StreamHandler
args = (sys.stderr,)
level = NOTSET
formatter = generic

[formatter_generic]
format = %(asctime)s %(levelname)-5.5s [%(name)s][%(threadName)s] %(message)s

# End logging configuration
26 changes: 26 additions & 0 deletions pyramid/paster_templates/pylons_minimal/development.ini_tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,29 @@ pipeline = egg:WebError#evalerror
use = egg:Paste#http
host = 0.0.0.0
port = 6543

# Begin logging configuration

[loggers]
keys = root

[handlers]
keys = console

[formatters]
keys = generic

[logger_root]
level = INFO
handlers = console

[handler_console]
class = StreamHandler
args = (sys.stderr,)
level = NOTSET
formatter = generic

[formatter_generic]
format = %(asctime)s %(levelname)-5.5s [%(name)s][%(threadName)s] %(message)s

# End logging configuration
12 changes: 6 additions & 6 deletions pyramid/paster_templates/pylons_sqla/+package+/__init__.py_tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@ from pyramid.settings import asbool

from pyramid_beaker import session_factory_from_settings

from sqlalchemy import engine_from_config

from {{package}}.models import initialize_sql

def main(global_config, **settings):
""" This function returns a Pyramid WSGI application.
"""
from {{package}}.models import initialize_sql
db_string = settings.get('db_string')
if db_string is None:
raise ValueError("No 'db_string' value in application "
"configuration.")
initialize_sql(db_string, asbool(settings.get('db_echo')))
engine = engine_from_config(settings, 'sqlalchemy.')
initialize_sql(engine)
config = Configurator(settings=settings)
session_factory = session_factory_from_settings(settings)
config.set_session_factory(session_factory)
Expand Down
3 changes: 1 addition & 2 deletions pyramid/paster_templates/pylons_sqla/+package+/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,7 @@ def populate():
DBSession.flush()
transaction.commit()

def initialize_sql(db_string, db_echo=False):
engine = create_engine(db_string, echo=db_echo)
def initialize_sql(engine):
DBSession.configure(bind=engine)
Base.metadata.bind = engine
Base.metadata.create_all(engine)
Expand Down
39 changes: 36 additions & 3 deletions pyramid/paster_templates/pylons_sqla/development.ini_tmpl
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
[app:{{project}}]
use = egg:{{project}}
reload_templates = true
mako.directories = {{package}}:templates
debug_authorization = false
debug_notfound = false
debug_templates = true
default_locale_name = en
db_string = sqlite:///%(here)s/tutorial.db
db_echo = true
mako.directories = {{package}}:templates
sqlalchemy.url = sqlite:///%(here)s/{{project}}.db
session.type = file
session.data_dir = %(here)s/data/sessions/data
session.lock_dir = %(here)s/data/sessions/lock
Expand All @@ -24,3 +23,37 @@ pipeline =
use = egg:Paste#http
host = 0.0.0.0
port = 6543

# Begin logging configuration

[loggers]
keys = root, sqlalchemy

[handlers]
keys = console

[formatters]
keys = generic

[logger_root]
level = INFO
handlers = console

[logger_sqlalchemy]
level = INFO
handlers =
qualname = sqlalchemy.engine
# "level = INFO" logs SQL queries.
# "level = DEBUG" logs SQL queries and results.
# "level = WARN" logs neither. (Recommended for production systems.)

[handler_console]
class = StreamHandler
args = (sys.stderr,)
level = NOTSET
formatter = generic

[formatter_generic]
format = %(asctime)s %(levelname)-5.5s [%(name)s][%(threadName)s] %(message)s

# End logging configuration
Original file line number Diff line number Diff line change
@@ -1,16 +1,14 @@
from pyramid.configuration import Configurator
from pyramid.settings import asbool
from sqlalchemy import engine_from_config

from {{package}}.models import initialize_sql

def main(global_config, **settings):
""" This function returns a Pyramid WSGI application.
"""
db_string = settings.get('db_string')
if db_string is None:
raise ValueError("No 'db_string' value in application configuration.")
db_echo = settings.get('db_echo', 'false')
initialize_sql(db_string, asbool(db_echo))
engine = engine_from_config(settings, 'sqlalchemy.')
initialize_sql(engine)
config = Configurator(settings=settings)
config.add_static_view('static', '{{package}}:static')
config.add_route('home', '/', view='{{package}}.views.my_view',
Expand Down
4 changes: 1 addition & 3 deletions pyramid/paster_templates/routesalchemy/+package+/models.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import transaction

from sqlalchemy import create_engine
from sqlalchemy import Column
from sqlalchemy import Integer
from sqlalchemy import Unicode
Expand Down Expand Up @@ -33,8 +32,7 @@ def populate():
session.flush()
transaction.commit()

def initialize_sql(db_string, db_echo=False):
engine = create_engine(db_string, echo=db_echo)
def initialize_sql(engine):
DBSession.configure(bind=engine)
Base.metadata.bind = engine
Base.metadata.create_all(engine)
Expand Down
43 changes: 38 additions & 5 deletions pyramid/paster_templates/routesalchemy/development.ini_tmpl
Original file line number Diff line number Diff line change
@@ -1,20 +1,53 @@
[app:{{package}}]
use = egg:{{package}}
[app:{{project}}]
use = egg:{{project}}
reload_templates = true
debug_authorization = false
debug_notfound = false
debug_templates = true
default_locale_name = en
db_string = sqlite:///%(here)s/{{package}}.db
db_echo = false
sqlalchemy.url = sqlite:///%(here)s/{{project}}.db

[pipeline:main]
pipeline =
egg:WebError#evalerror
egg:repoze.tm2#tm
{{package}}
{{project}}

[server:main]
use = egg:Paste#http
host = 0.0.0.0
port = 6543

# Begin logging configuration

[loggers]
keys = root, sqlalchemy

[handlers]
keys = console

[formatters]
keys = generic

[logger_root]
level = INFO
handlers = console

[logger_sqlalchemy]
level = INFO
handlers =
qualname = sqlalchemy.engine
# "level = INFO" logs SQL queries.
# "level = DEBUG" logs SQL queries and results.
# "level = WARN" logs neither. (Recommended for production systems.)

[handler_console]
class = StreamHandler
args = (sys.stderr,)
level = NOTSET
formatter = generic

[formatter_generic]
format = %(asctime)s %(levelname)-5.5s [%(name)s][%(threadName)s] %(message)s

# End logging configuration
Loading

0 comments on commit 957f614

Please sign in to comment.