Merge lp:~james-w/pkgme-service/log-oopses into lp:pkgme-service

Proposed by James Westby
Status: Merged
Approved by: Jonathan Lange
Approved revision: 40
Merged at revision: 39
Proposed branch: lp:~james-w/pkgme-service/log-oopses
Merge into: lp:pkgme-service
Diff against target: 145 lines (+69/-3)
9 files modified
.bzrignore (+1/-0)
dev_config/templates/production_credentials.cfg.erb (+6/-0)
django_project/dev.cfg (+6/-0)
django_project/main.cfg (+35/-0)
django_project/production_credentials.cfg.example (+6/-0)
src/djpkgme/templates/404.html (+5/-0)
src/djpkgme/templates/500.html (+5/-0)
src/djpkgme/urls.py (+1/-0)
src/djpkgme/views.py (+4/-3)
To merge this branch: bzr merge lp:~james-w/pkgme-service/log-oopses
Reviewer Review Type Date Requested Status
Jonathan Lange (community) Approve
Review via email: mp+89999@code.launchpad.net

Commit message

Add the configuration to have django errors logged to a file.

Description of the change

Hi,

This adds the configuration for django's logging framework to log
everything at WARNING or higher to a log file.

It also does a couple of things that will help with using this:

  * Adds /pkgme/+oops URL that generates an exception on purpose.
  * Adds a template for 404 so that they don't turn in to 500s
  * Adds a template for 500 so that we know what the real exception is, not
    the one that says "You don't have a 500.html template."

This will require some co-ordination with IS around deployment so that the
config is in place first, and the config needs to be created by puppet
so that it can point to the right log dir. I'll propose a branch to add
this to the template.

Thanks,

James

To post a comment you must log in.
lp:~james-w/pkgme-service/log-oopses updated
39. By James Westby

Also add the stanza to the dev_config template.

40. By James Westby

Reset debug.

Revision history for this message
Jonathan Lange (jml) wrote :

Looks good.

Why do we set the log dir for Django in the example credentials, but set the output directory for pkgme in the production.cfg?

Is there some wiki page we should update for tricky deployments?

review: Approve
Revision history for this message
James Westby (james-w) wrote :

On Wed, 25 Jan 2012 13:57:44 -0000, Jonathan Lange <email address hidden> wrote:
> Review: Approve
>
> Looks good.
>
> Why do we set the log dir for Django in the example credentials, but set the output directory for pkgme in the production.cfg?

We have to set the log dir in the production_credentials as it will
change depending on the instance (production/staging), so it should be
managed by puppet.

The fact that the output directory is the same for pkgme is a bit of an
oddity I guess.

> Is there some wiki page we should update for tricky deployments?

https://wiki.canonical.com/InformationInfrastructure/WebOps/CA/PkgmeServiceProductionStatus

I'll update it when the branch lands and I have the revno.

Thanks,

James

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file '.bzrignore'
2--- .bzrignore 2012-01-13 01:03:04 +0000
3+++ .bzrignore 2012-01-24 21:19:23 +0000
4@@ -9,3 +9,4 @@
5 sourcecode/*
6 django_project/production_paths.py
7 django_project/production_credentials.cfg
8+django.log
9
10=== modified file 'dev_config/templates/production_credentials.cfg.erb'
11--- dev_config/templates/production_credentials.cfg.erb 2012-01-18 23:45:14 +0000
12+++ dev_config/templates/production_credentials.cfg.erb 2012-01-24 21:19:23 +0000
13@@ -25,3 +25,9 @@
14 myapps_consumer_key =
15 myapps_token =
16 myapps_token_secret =
17+
18+[django_file_logging_handler]
19+level = WARNING
20+class = logging.handlers.WatchedFileHandler
21+formatter = verbose
22+filename = <%= basedir %>/django.log
23
24=== modified file 'django_project/dev.cfg'
25--- django_project/dev.cfg 2012-01-09 22:52:57 +0000
26+++ django_project/dev.cfg 2012-01-24 21:19:23 +0000
27@@ -15,6 +15,12 @@
28 djkombu
29 databases = databases
30
31+[django_file_logging_handler]
32+level = WARNING
33+class = logging.handlers.WatchedFileHandler
34+formatter = verbose
35+filename = django.log
36+
37 [databases]
38 default = default_database
39
40
41=== modified file 'django_project/main.cfg'
42--- django_project/main.cfg 2012-01-10 14:33:32 +0000
43+++ django_project/main.cfg 2012-01-24 21:19:23 +0000
44@@ -33,3 +33,38 @@
45 django.contrib.messages.middleware.MessageMiddleware
46 root_urlconf = django_project.urls
47 test_runner = djcelery.contrib.test_runner.CeleryTestSuiteRunner
48+logging = django_logging
49+
50+[django_logging]
51+version = 1
52+disable_existing_loggers = True
53+formatters = django_logging_formatters
54+handlers = django_logging_handlers
55+loggers = django_logging_loggers
56+root = django_logging_root
57+
58+[django_logging_root]
59+level = WARNING
60+
61+[django_logging_loggers]
62+django = django_logger
63+
64+[django_logger]
65+handlers = file
66+level = WARNING
67+
68+[django_logging_handlers]
69+file = django_file_logging_handler
70+null = django_null_logging_handler
71+
72+[django_null_logging_handler]
73+level = DEBUG
74+class = django.utils.log.NullHandler
75+
76+[django_logging_formatters]
77+verbose = django_verbose_logging_formatter
78+
79+[django_verbose_logging_formatter]
80+# Double escaped as configglue interpolates once, and we need the rest to survive
81+# until django interpolates.
82+format = %%(levelname)s %%(asctime)s %%(module)s %%(process)d %%(thread)d %%(message)s
83
84=== modified file 'django_project/production_credentials.cfg.example'
85--- django_project/production_credentials.cfg.example 2012-01-09 22:52:57 +0000
86+++ django_project/production_credentials.cfg.example 2012-01-24 21:19:23 +0000
87@@ -31,3 +31,9 @@
88 myapps_consumer_key =
89 myapps_token =
90 myapps_token_secret =
91+
92+[django_file_logging_handler]
93+level = WARNING
94+class = logging.handlers.WatchedFileHandler
95+formatter = verbose
96+filename = /var/log/pkgme-service/django.log
97
98=== added directory 'src/djpkgme/templates'
99=== added file 'src/djpkgme/templates/404.html'
100--- src/djpkgme/templates/404.html 1970-01-01 00:00:00 +0000
101+++ src/djpkgme/templates/404.html 2012-01-24 21:19:23 +0000
102@@ -0,0 +1,5 @@
103+<html>
104+ <body>
105+ <h1>Not Found</h1>
106+ </body>
107+</html>
108
109=== added file 'src/djpkgme/templates/500.html'
110--- src/djpkgme/templates/500.html 1970-01-01 00:00:00 +0000
111+++ src/djpkgme/templates/500.html 2012-01-24 21:19:23 +0000
112@@ -0,0 +1,5 @@
113+<html>
114+<body>
115+ <h1>Error</h1>
116+</body>
117+</html>
118
119=== modified file 'src/djpkgme/urls.py'
120--- src/djpkgme/urls.py 2011-08-31 19:37:43 +0000
121+++ src/djpkgme/urls.py 2012-01-24 21:19:23 +0000
122@@ -5,5 +5,6 @@
123
124 urlpatterns = patterns('',
125 url(r'^$', views.index),
126+ url(r'^\+oops$', views.oops),
127 url(r'^api/', include(djpkgme.api.urls)),
128 )
129
130=== modified file 'src/djpkgme/views.py'
131--- src/djpkgme/views.py 2011-11-28 17:20:42 +0000
132+++ src/djpkgme/views.py 2012-01-24 21:19:23 +0000
133@@ -1,8 +1,9 @@
134-from django.http import HttpResponseRedirect, HttpResponse
135-
136-from .tasks import GuessPackagingDetailsTask
137+from django.http import HttpResponse
138
139 ALL_CLEAR = 'Hello world!'
140
141 def index(request):
142 return HttpResponse(ALL_CLEAR)
143+
144+def oops(request):
145+ raise AssertionError("Manually generated OOPS")

Subscribers

People subscribed via source and target branches