Commits

Dan Colish committed 6c1ba5f

fix logging, use AsyncWriter from whoosh

Comments (0)

Files changed (9)

 [lodgeit]
+debug = True
 dburi = sqlite:///lodgeit.db
 secret_key = no secret key
 static_path = lodgeit/static

lodgeit/__init__.py

     :copyright: 2007 by Armin Ronacher.
     :license: BSD
 """
-from lodgeit.utilities import config
+from lodgeit.utilities import config, log
 from lodgeit.wsgi.application import make_app

lodgeit/controllers/pastes.py

     :copyright: 2007-2008 by Armin Ronacher, Christopher Grebs.
     :license: BSD
 """
+import logging
+
 from werkzeug import redirect, Response
 from werkzeug.exceptions import NotFound
 
 from lodgeit.lib.pagination import generate_pagination
 from lodgeit.search import index, search
 
+log = logging.getLogger(__name__)
+
 
 class PasteController(object):
     """Provides all the handler callback for paste related stuff."""
                 db.session.add(paste)
                 db.session.commit()
                 local.request.session['language'] = language
+                log.debug("indexing paste %s", paste)
                 index(paste)
                 return redirect(url_for('pastes/show_paste',
                                         paste=paste))

lodgeit/database.py

 
 metadata = MetaData()
 
-engine = create_engine(config.get('lodgeit', 'dburi'), convert_unicode=True)
+engine = create_engine(config.get('lodgeit', 'dburi'),
+                       convert_unicode=True,
+                       echo=False)
 session = sessionmaker(bind=engine,
                        autoflush=True,
                        autocommit=False)

lodgeit/search.py

+import logging
 from os import makedirs
 from os.path import exists
 
 from whoosh.fields import ID, Schema, TEXT
 from whoosh.index import create_in, open_dir
 from whoosh.qparser import QueryParser
-
+from whoosh.writing import AsyncWriter
 from lodgeit import config
 from lodgeit.models import Paste
 
 paste_schema = Schema(paste_id=ID(stored=True),
                       code=TEXT(stored=True))
 
+log = logging.getLogger(__name__)
+
 
 def build_indexer():
     global ix
 
 def index(paste):
     global ix
-    writer = ix.writer()
+    writer = AsyncWriter(ix)
     paste_doc = {u'paste_id': unicode(paste.paste_id), u'code': paste.code}
+    log.debug("indexing: %s", paste_doc)
     writer.add_document(**paste_doc)
     writer.commit()
 

lodgeit/utilities.py

 from ConfigParser import ParsingError, ConfigParser
+import logging
 from os.path import abspath
 
 config = ConfigParser()
 if not config.read(abspath('conf/lodgeit.ini')):
     raise ParsingError("Bad parse")
+
+FORMAT = '[%(levelname)s] %(asctime)-15s %(name)s - %(message)s'
+
+
+class SQLFilter(logging.Filter):
+    def filter(record):
+        return 'sqlalchemy' in record.name
+
+
+logging.basicConfig(format=FORMAT)
+log = logging.getLogger()
+log.setLevel(logging.DEBUG)

lodgeit/wsgi/application.py

 """
 import os
 from datetime import datetime, timedelta
+import logging
 
 from werkzeug import SharedDataMiddleware, ClosingIterator
 from werkzeug.exceptions import HTTPException, NotFound
 from lodgeit.wsgi.urls import urlmap
 from lodgeit.wsgi.utils import COOKIE_NAME, Request, jinja_environment
 
+log = logging.getLogger(__name__)
+
 
 class LodgeIt(object):
     """The WSGI Application"""
 
         try:
             endpoint, args = urls.match(request.path)
+            log.debug('%s %s', request.method, endpoint)
             handler = get_controller(endpoint)
             resp = handler(**args)
         except NotFound:
     static_path = os.path.abspath(config.get('lodgeit', 'static_path'))
     app = LodgeIt()
     if debug:
-        app.engine.echo = True
+        logger = logging.getLogger()
+        logger.setLevel(logging.DEBUG)
     if not shell:
         # we don't need access to the shared data middleware in shell mode
         app = SharedDataMiddleware(app, {'/static': static_path})

lodgeit/wsgi/templates/rss.html

     {%- for item in items %}
     <item>
       <title>Paste #{{ item.paste_id }}</title>
-      <link>{{ url_for('pastes/show_paste', identifier=item.paste_id, external=True) }}</link>
-      <guid>{{ url_for('pastes/show_paste', identifier=item.paste_id, external=True) }}</guid>
+      <link>{{ url_for('pastes/show_paste', paste=item, external=True) }}</link>
+      <guid>{{ url_for('pastes/show_paste', paste=item, external=True) }}</guid>
       <description>{{ item.render_preview() }}</description>
     </item>
     {%- endfor %}

lodgeit/wsgi/utils.py

         gettext=request.translations.ugettext,
         ngettext=request.translations.ungettext
     )
-    return jinja_environment.get_template(template_name).render(context)
+    return jinja_environment.get_template(template_name).stream(context)
 
 
 def render_to_response(template_name, mimetype='text/html', **context):