Skip to content

Commit

Permalink
日志记录
Browse files Browse the repository at this point in the history
  • Loading branch information
stacklens committed Jul 17, 2019
1 parent fac8949 commit 1e2ad20
Show file tree
Hide file tree
Showing 10 changed files with 88 additions and 4 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@
34. [锚点定位](https://www.dusaiphoto.com/article/detail/65/)
35. [第三方登录](https://www.dusaiphoto.com/article/detail/66/)
36. [自动化测试](https://www.dusaiphoto.com/article/detail/67/)
37. [日志记录](https://www.dusaiphoto.com/article/detail/68/)

以及:
- [小功能集合](https://www.dusaiphoto.com/article/detail/53/)
Expand Down
Binary file modified article/__pycache__/views.cpython-37.pyc
Binary file not shown.
14 changes: 11 additions & 3 deletions article/views.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# 引入redirect重定向模块
from django.shortcuts import render, redirect
from django.shortcuts import render, redirect, get_object_or_404
# 引入User模型
from django.contrib.auth.models import User
# 引入HttpResponse
Expand All @@ -26,6 +26,12 @@
from django.views.generic import ListView, DetailView
from django.views.generic.edit import CreateView

# from my_blog.settings import LOGGING
# import logging

# logging.config.dictConfig(LOGGING)
# logger = logging.getLogger('django.request')


# 文章列表
def article_list(request):
Expand Down Expand Up @@ -82,8 +88,10 @@ def article_list(request):
# 文章详情
def article_detail(request, id):
# 取出相应的文章
article = ArticlePost.objects.get(id=id)

# article = ArticlePost.objects.get(id=id)
# logger.warning('Something went wrong!')
article = get_object_or_404(ArticlePost, id=id)

# 取出文章评论
comments = Comment.objects.filter(article=id)

Expand Down
Binary file modified db.sqlite3
Binary file not shown.
4 changes: 4 additions & 0 deletions logs/debug.log
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
WARNING 2019-07-18 21:57:38,716 log 3868 2684 Not Found: /article/article-detail/9999/
WARNING 2019-07-17 22:24:53,280 log 16160 16408 Not Found: /article/article-detail/9999/
WARNING 2019-07-17 22:25:19,715 views 3060 16916 Something went wrong!
WARNING 2019-07-17 22:25:19,721 log 3060 16916 Not Found: /article/article-detail/9999/
1 change: 1 addition & 0 deletions logs/debug.log.2019-07-17
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
WARNING 2019-07-17 21:56:45,912 log 8484 15904 Not Found: /article/article-detail/9999/
Binary file modified media/article/20190226/4.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added media/avatar/20190707/ultrasmall.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified my_blog/__pycache__/settings.cpython-37.pyc
Binary file not shown.
72 changes: 71 additions & 1 deletion my_blog/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -200,4 +200,74 @@
# 设置站点
SITE_ID = 1
# 重定向 url
LOGIN_REDIRECT_URL = '/'
LOGIN_REDIRECT_URL = '/'

# LOGGING = {
# 'version': 1,
# 'handlers': {
# 'file': {
# 'level': 'INFO',
# 'class': 'logging.FileHandler',
# 'filename': os.path.join(BASE_DIR, 'logs/debug.log'),
# },
# },
# 'loggers': {
# 'django': {
# 'handlers': ['file'],
# 'level': 'INFO',
# },
# },
# }

# LOGGING = {
# 'version': 1,
# 'disable_existing_loggers': False,
# 'formatters': {
# 'verbose': {
# 'format': '{levelname} {asctime} {module} {process:d} {thread:d} {message}',
# 'style': '{',
# },
# 'simple': {
# 'format': '{levelname} {message}',
# 'style': '{',
# },
# },
# 'filters': {
# 'require_debug_true': {
# '()': 'django.utils.log.RequireDebugTrue',
# },
# },
# 'handlers': {
# 'console': {
# 'level': 'INFO',
# 'filters': ['require_debug_true'],
# 'class': 'logging.StreamHandler',
# 'formatter': 'simple'
# },
# 'mail_admins': {
# 'level': 'ERROR',
# 'class': 'django.utils.log.AdminEmailHandler',
# 'formatter': 'verbose',
# },
# 'file': {
# 'level': 'WARNING',
# # 'class': 'logging.FileHandler',
# 'class': 'logging.handlers.TimedRotatingFileHandler',
# 'when': 'midnight',
# 'backupCount': 30,
# 'filename': os.path.join(BASE_DIR, 'logs/debug.log'),
# 'formatter': 'verbose',
# },
# },
# 'loggers': {
# 'django': {
# 'handlers': ['console'],
# 'propagate': True,
# },
# 'django.request': {
# 'handlers': ['file', 'mail_admins'],
# 'level': 'WARNING',
# 'propagate': False,
# },
# }
# }

0 comments on commit 1e2ad20

Please sign in to comment.