Skip to content

Commit

Permalink
Improve logging in useful places.
Browse files Browse the repository at this point in the history
  • Loading branch information
David Read committed Jun 15, 2012
1 parent 04ca419 commit 6780e91
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 6 deletions.
2 changes: 2 additions & 0 deletions ckan/controllers/package.py
Expand Up @@ -592,6 +592,8 @@ def _save_new(self, context, package_type=None):

def _save_edit(self, name_or_id, context):
from ckan.lib.search import SearchIndexError
log.debug('Package save request name: %s POST: %r',
name_or_id, request.POST)
try:
data_dict = clean_dict(unflatten(
tuplize_dict(parse_params(request.POST))))
Expand Down
6 changes: 6 additions & 0 deletions ckan/lib/authenticator.py
@@ -1,8 +1,12 @@
import logging

from zope.interface import implements
from repoze.who.interfaces import IAuthenticator

from ckan.model import User, Session

log = logging.getLogger(__name__)

class OpenIDAuthenticator(object):
implements(IAuthenticator)

Expand All @@ -25,8 +29,10 @@ def authenticate(self, environ, identity):
return None
user = User.by_name(identity.get('login'))
if user is None:
log.debug('Login failed - username %r not found', identity.get('login'))
return None
if user.validate_password(identity.get('password')):
return user.name
log.debug('Login as %r failed - password not valid', identity.get('login'))
return None

3 changes: 3 additions & 0 deletions ckan/lib/base.py
Expand Up @@ -29,6 +29,8 @@
from ckan.lib.helpers import json
import ckan.model as model

log = logging.getLogger(__name__)

PAGINATE_ITEMS_PER_PAGE = 50

APIKEY_HEADER_NAME_KEY = 'apikey_header_name'
Expand Down Expand Up @@ -139,6 +141,7 @@ def render_template():
response.headers["Cache-Control"] = "private"
# Prevent any further rendering from being cached.
request.environ['__no_cache__'] = True
log.debug('Template cache-control: %s' % response.headers["Cache-Control"])

# Render Time :)
try:
Expand Down
13 changes: 7 additions & 6 deletions ckan/lib/search/__init__.py
Expand Up @@ -128,33 +128,34 @@ def rebuild(package_id=None,only_missing=False,force=False,refresh=False):
If a dataset id is provided, only this dataset will be reindexed.
When reindexing all datasets, if only_missing is True, only the
datasets not already indexed will be processed. If force equals
True, if an execption is found, the exception will be logged, but
True, if an exception is found, the exception will be logged, but
the process will carry on.
'''
from ckan import model
log.debug("Rebuilding search index...")
log.info("Rebuilding search index...")

package_index = index_for(model.Package)

if package_id:
pkg_dict = get_action('package_show')(
{'model': model, 'ignore_auth': True, 'validate': False},
{'id': package_id})
log.info('Indexing just package %r...', pkg_dict['name'])
package_index.remove_dict(pkg_dict)
package_index.insert_dict(pkg_dict)
else:
package_ids = [r[0] for r in model.Session.query(model.Package.id).filter(model.Package.state == 'active').all()]
if only_missing:
log.debug('Indexing only missing packages...')
log.info('Indexing only missing packages...')
package_query = query_for(model.Package)
indexed_pkg_ids = set(package_query.get_all_entity_ids(max_results=len(package_ids)))
package_ids = set(package_ids) - indexed_pkg_ids # Packages not indexed

if len(package_ids) == 0:
log.debug('All datasets are already indexed')
log.info('All datasets are already indexed')
return
else:
log.debug('Rebuilding the whole index...')
log.info('Rebuilding the whole index...')
# When refreshing, the index is not previously cleared
if not refresh:
package_index.clear()
Expand All @@ -176,7 +177,7 @@ def rebuild(package_id=None,only_missing=False,force=False,refresh=False):
raise

model.Session.commit()
log.debug('Finished rebuilding search index.')
log.info('Finished rebuilding search index.')

def check():
from ckan import model
Expand Down

0 comments on commit 6780e91

Please sign in to comment.