Configuring splunk for django » History » Version 3
Luke Murphey, 02/28/2013 08:01 AM
1 | 1 | Luke Murphey | h1. Configuring Splunk for Django |
---|---|---|---|
2 | 1 | Luke Murphey | |
3 | 1 | Luke Murphey | h2. Configuring Django |
4 | 1 | Luke Murphey | |
5 | 1 | Luke Murphey | Django needs to be setup to log files in a particular way for Splunk to read in a way that they can be parsed. To do so, set a formatter to output the time and severity to the logs messages using a formatter of "%(asctime)s [%(levelname)s] %(name)s: %(message)s". |
6 | 1 | Luke Murphey | |
7 | 1 | Luke Murphey | Below is a logging configuration that can be used with the app, add it to your settings file: |
8 | 1 | Luke Murphey | |
9 | 1 | Luke Murphey | <pre> |
10 | 1 | Luke Murphey | <code class="python"> |
11 | 1 | Luke Murphey | LOGGING = { |
12 | 1 | Luke Murphey | 'version': 1, |
13 | 1 | Luke Murphey | 'disable_existing_loggers': False, |
14 | 1 | Luke Murphey | 'formatters': { |
15 | 1 | Luke Murphey | 'standard': { |
16 | 1 | Luke Murphey | 'format': '%(asctime)s [%(levelname)s] %(name)s: %(message)s' |
17 | 1 | Luke Murphey | }, |
18 | 1 | Luke Murphey | }, |
19 | 1 | Luke Murphey | 'filters': { |
20 | 1 | Luke Murphey | 'require_debug_false': { |
21 | 1 | Luke Murphey | '()': 'django.utils.log.RequireDebugFalse' |
22 | 1 | Luke Murphey | } |
23 | 1 | Luke Murphey | }, |
24 | 1 | Luke Murphey | 'handlers': { |
25 | 1 | Luke Murphey | 'null': { |
26 | 1 | Luke Murphey | 'level':'DEBUG', |
27 | 1 | Luke Murphey | 'class':'django.utils.log.NullHandler', |
28 | 1 | Luke Murphey | }, |
29 | 1 | Luke Murphey | 'console':{ |
30 | 1 | Luke Murphey | 'level':'DEBUG', |
31 | 1 | Luke Murphey | 'class':'logging.StreamHandler' |
32 | 1 | Luke Murphey | }, |
33 | 1 | Luke Murphey | 'default': { |
34 | 1 | Luke Murphey | 'level':'DEBUG', |
35 | 1 | Luke Murphey | 'class':'logging.handlers.RotatingFileHandler', |
36 | 1 | Luke Murphey | 'filename': '../var/log/app.log', # Make sure that this path exists, change as necessary |
37 | 1 | Luke Murphey | 'maxBytes': 1024*1024*5, # 5 MB |
38 | 1 | Luke Murphey | 'backupCount': 5, |
39 | 1 | Luke Murphey | 'formatter':'standard', |
40 | 1 | Luke Murphey | } |
41 | 1 | Luke Murphey | }, |
42 | 1 | Luke Murphey | 'loggers': { |
43 | 1 | Luke Murphey | 'django.db': { |
44 | 1 | Luke Murphey | 'handlers': ['default'], |
45 | 3 | Luke Murphey | 'level': 'DEBUG', # Set this to ERROR on production hosts since the database logs are very verbose |
46 | 3 | Luke Murphey | 'propagate': False, |
47 | 1 | Luke Murphey | }, |
48 | 1 | Luke Murphey | '': { |
49 | 1 | Luke Murphey | 'handlers': ['default'], |
50 | 1 | Luke Murphey | 'level': 'DEBUG', |
51 | 1 | Luke Murphey | 'propagate': True, |
52 | 1 | Luke Murphey | }, |
53 | 1 | Luke Murphey | 'django.request': { |
54 | 1 | Luke Murphey | 'handlers': ['default'], |
55 | 3 | Luke Murphey | 'level': 'DEBUG', # Set this to ERROR on production hosts if you want to avoid lots of warnings for 404 file-not-found notices |
56 | 3 | Luke Murphey | 'propagate': False, |
57 | 1 | Luke Murphey | }, |
58 | 1 | Luke Murphey | } |
59 | 1 | Luke Murphey | } |
60 | 1 | Luke Murphey | </code> |
61 | 1 | Luke Murphey | </pre> |
62 | 2 | Luke Murphey | |
63 | 2 | Luke Murphey | h2. Configuring Splunk |
64 | 2 | Luke Murphey | |
65 | 2 | Luke Murphey | Setup Splunk to monitor the logs files from your Django installation. Make sure to set the sourcetype to "django". See "docs.splunk.com":http://docs.splunk.com/Documentation/Splunk/latest/Data/MonitorFilesandDirectories for details on how to monitor files with Splunk. |