Skip to content

Commit 435bfab

Browse files
committed
add sentry log
1 parent 8d3e4f0 commit 435bfab

File tree

3 files changed

+41
-9
lines changed

3 files changed

+41
-9
lines changed

DjangoBlog/settings.py

Lines changed: 39 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
"""
1212
import sys
1313
import os
14+
import raven
1415

1516
# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
1617
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
@@ -30,6 +31,17 @@
3031
ALLOWED_HOSTS = ['*', 'www.lylinux.net', '127.0.0.1', 'example.com']
3132
# Application definition
3233

34+
35+
SITE_ROOT = os.path.dirname(os.path.abspath(__file__))
36+
SITE_ROOT = os.path.abspath(os.path.join(SITE_ROOT, '../'))
37+
38+
RAVEN_CONFIG = {
39+
'dsn': os.environ.get('SENTRY_DSN'),
40+
# If you are using git, you can also automatically configure the
41+
# release based on the git info.
42+
'release': raven.fetch_git_sha(os.path.abspath(SITE_ROOT)),
43+
}
44+
3345
INSTALLED_APPS = [
3446
# 'django.contrib.admin',
3547
'django.contrib.admin.apps.SimpleAdminConfig',
@@ -40,6 +52,7 @@
4052
'django.contrib.staticfiles',
4153
'django.contrib.sites',
4254
'django.contrib.sitemaps',
55+
'raven.contrib.django.raven_compat',
4356
'pagedown',
4457
'haystack',
4558
'blog',
@@ -138,9 +151,6 @@
138151
# https://docs.djangoproject.com/en/1.10/howto/static-files/
139152

140153

141-
SITE_ROOT = os.path.dirname(os.path.abspath(__file__))
142-
SITE_ROOT = os.path.abspath(os.path.join(SITE_ROOT, '../'))
143-
144154
HAYSTACK_CONNECTIONS = {
145155
'default': {
146156
'ENGINE': 'DjangoBlog.whoosh_cn_backend.WhooshEngine',
@@ -193,7 +203,7 @@
193203
# Emial:
194204
EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend'
195205

196-
#EMAIL_USE_TLS = True
206+
# EMAIL_USE_TLS = True
197207
EMAIL_USE_SSL = True
198208

199209
EMAIL_HOST = 'smtp.mxhichina.com'
@@ -206,15 +216,20 @@
206216
ADMINS = [('liangliang', 'liangliangyy@gmail.com')]
207217
# 微信管理员密码(两次md5获得)
208218
WXADMIN = '995F03AC401D6CABABAEF756FC4D43C7'
219+
209220
LOGGING = {
210221
'version': 1,
211222
'disable_existing_loggers': False,
223+
'root': {
224+
'level': 'WARNING',
225+
'handlers': ['sentry', 'console', 'log_file'],
226+
},
212227
'formatters': {
213228
'verbose': {
214229
'format': '[%(asctime)s] %(levelname)s [%(name)s.%(funcName)s:%(lineno)d] %(message)s',
215230
},
216231
'simple': {
217-
'format': '%(levelname)s %(asctime)s %(message)s'
232+
'format': '[%(asctime)s] %(levelname)s [%(name)s.%(funcName)s:%(lineno)d] %(message)s',
218233
},
219234
},
220235
'filters': {
@@ -229,7 +244,7 @@
229244
'log_file': {
230245
'level': 'INFO',
231246
'class': 'logging.handlers.RotatingFileHandler',
232-
'filename': 'djangoblog.log',
247+
'filename': 'xiaobiaobai.log',
233248
'maxBytes': 16777216, # 16 MB
234249
'formatter': 'verbose'
235250
},
@@ -246,19 +261,34 @@
246261
'level': 'ERROR',
247262
'filters': ['require_debug_false'],
248263
'class': 'django.utils.log.AdminEmailHandler'
249-
}
264+
},
265+
'sentry': {
266+
'level': 'ERROR', # To capture more than ERROR, change to WARNING, INFO, etc.
267+
'class': 'raven.contrib.django.raven_compat.handlers.SentryHandler',
268+
'tags': {'custom-tag': 'x'},
269+
},
250270
},
251271
'loggers': {
252-
'djangoblog': {
272+
'xiaobiaobai': {
253273
'handlers': ['log_file', 'console'],
254274
'level': 'INFO',
255275
'propagate': True,
256276
},
257277
'django.request': {
258-
'handlers': ['mail_admins'],
278+
'handlers': ['mail_admins', 'sentry'],
259279
'level': 'ERROR',
260280
'propagate': False,
261281
},
282+
'raven': {
283+
'level': 'DEBUG',
284+
'handlers': ['console'],
285+
'propagate': False,
286+
},
287+
'sentry.errors': {
288+
'level': 'DEBUG',
289+
'handlers': ['console'],
290+
'propagate': False,
291+
},
262292
}
263293
}
264294

requirements.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ pyparsing==2.2.0
2626
python-memcached==1.59
2727
python-slugify==1.2.5
2828
pytz==2018.4
29+
raven==6.9.0
2930
rcssmin==1.0.6
3031
requests==2.18.4
3132
rjsmin==1.0.12

travis_test/requirements.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ PyMySQL==0.8.1
2525
pyparsing==2.2.0
2626
python-slugify==1.2.5
2727
pytz==2018.4
28+
raven==6.9.0
2829
rcssmin==1.0.6
2930
requests==2.18.4
3031
rjsmin==1.0.12

0 commit comments

Comments
 (0)