Skip to content
Browse files

copying input style logging

  • Loading branch information...
1 parent 48610ff commit 407a89c46cb20faec08342054f1dd3e95e795367 @ozten ozten committed Aug 22, 2011
Showing with 93 additions and 0 deletions.
  1. +5 −0 apps/landing/views.py
  2. +5 −0 apps/phonebook/views.py
  3. +69 −0 log_settings.py
  4. +14 −0 settings.py
View
5 apps/landing/views.py
@@ -2,12 +2,17 @@
from django.http import HttpResponse
+import commonware.log
+
+log = commonware.log.getLogger('i.landing')
+
def about(request):
return jingo.render(request, 'landing/about.html')
def home(request):
+ log.warning('homepage requested profile_id')
return jingo.render(request, 'landing/home.html')
View
5 apps/phonebook/views.py
@@ -12,12 +12,14 @@
import jingo
from tower import ugettext as _
+import commonware.log
from commons.urlresolvers import reverse
from larper import UserSession, AdminSession, NO_SUCH_PERSON
from larper import MOZILLA_IRC_SERVICE_URI
from phonebook import forms
from phonebook.models import Invite
+log = commonware.log.getLogger('i.phonebook')
def vouch_required(f):
"""
@@ -29,6 +31,7 @@ def wrapped(request, *args, **kwargs):
if request.user.is_vouched():
return f(request, *args, **kwargs)
else:
+ log.warning('vouch_required forbidding access')
return HttpResponseForbidden(_('You must be vouched to do this.'))
return wrapped
@@ -40,11 +43,13 @@ def profile_uid(request, unique_id):
random user id.
"""
ldap = UserSession.connect(request)
+ log.warning('profile_uid [%s]' % unique_id)
try:
person = ldap.get_by_unique_id(unique_id)
if person.last_name:
return _profile(request, person)
except NO_SUCH_PERSON:
+ log.warning('profile_uid Sending 404 for [%s]' % unique_id)
raise Http404
View
69 log_settings.py
@@ -0,0 +1,69 @@
+import logging
+import logging.handlers
+
+from django.conf import settings
+
+import commonware.log
+import dictconfig
+
+
+class NullHandler(logging.Handler):
+
+ def emit(self, record):
+ pass
+
+
+base_fmt = ('%(name)s:%(levelname)s %(message)s '
+ ':%(pathname)s:%(lineno)s')
+
+cfg = {
+ 'version': 1,
+ 'filters': {},
+ 'formatters': {
+ 'debug': {
+ '()': commonware.log.Formatter,
+ 'datefmt': '%H:%M:%s',
+ 'format': '%(asctime)s ' + base_fmt,
+ },
+ 'prod': {
+ '()': commonware.log.Formatter,
+ 'datefmt': '%H:%M:%s',
+ 'format': '%s: [%%(REMOTE_ADDR)s] %s' % (settings.SYSLOG_TAG,
+ base_fmt),
+ },
+ },
+ 'handlers': {
+ 'console': {
+ '()': logging.StreamHandler,
+ 'formatter': 'debug',
+ },
+ 'syslog': {
+ '()': logging.handlers.SysLogHandler,
+ 'facility': logging.handlers.SysLogHandler.LOG_LOCAL7,
+ 'formatter': 'prod',
+ },
+ 'null': {
+ '()': NullHandler,
+ }
+ },
+ 'loggers': {
+ 'i': {},
+ },
+ 'root': {},
+}
+
+for key, value in settings.LOGGING.items():
+ cfg[key].update(value)
+
+# Set the level and handlers for all loggers.
+for logger in cfg['loggers'].values() + [cfg['root']]:
+ syslog = settings.HAS_SYSLOG and not settings.DEBUG
+ if 'handlers' not in logger:
+ logger['handlers'] = ['syslog' if syslog else 'console']
+ if 'level' not in logger:
+ logger['level'] = settings.LOG_LEVEL
+ if logger is not cfg['root'] and 'propagate' not in logger:
+ logger['propagate'] = False
+
+dictconfig.dictConfig(cfg)
+
View
14 settings.py
@@ -1,6 +1,7 @@
# -*- coding: utf-8 -*-
# Django settings for the mozillians project.
import ldap
+import logging
import os
import socket
@@ -23,6 +24,19 @@
DATABASES = {} # See settings_local.
+## Log settings
+LOG_LEVEL = logging.DEBUG
+HAS_SYSLOG = True
+SYSLOG_TAG = "http_app_reporter"
+LOGGING_CONFIG = None
+LOGGING = {
+ 'loggers': {
+ 'i.landing': {'level': logging.INFO},
+ 'i.phonebook': {'level': logging.INFO},
+ },
+}
+
+
# Site ID is used by Django's Sites framework.
SITE_ID = 1

0 comments on commit 407a89c

Please sign in to comment.
Something went wrong with that request. Please try again.