首页Django正文

为什么console里面的输出都打到日志里面了

提问已结 2 28
lyhabc
lyhabcDjango实战会员2018年8月20日 18:54

settings里面的配置

LOGGING = { 'version': 1, # 版本为1,默认即可 'disable_existing_loggers': False, 'formatters': { 'verbose': { 'format': '%(levelname)s %(asctime)s %(module)s %(process)d %(thread)d %(message)s' }, 'simple': { 'format': '%(levelname)s %(message)s' }, }, 'handlers': { 'file': { 'level': 'DEBUG', 'class': 'logging.FileHandler', 'filename': 'debug.log', }, 'console': { 'level': 'DEBUG', 'class': 'logging.StreamHandler', }, }, 'loggers': { 'django': { 'handlers': ['file'], 'level': 'DEBUG', 'propagate': False, # 不要传播 }, }, }

问题一:我的handlers只指定了file,但是他吧日志也打到debug.log里面了,不知道为什么 问题二:为什么qs的sql语句也打印出来了,我明明没有使用connection

(0.001) 
            SELECT name, type FROM sqlite_master
            WHERE type in ('table', 'view') AND NOT name='sqlite_sequence'
            ORDER BY name; args=None
(0.001) SELECT "django_migrations"."app", "django_migrations"."name" FROM "django_migrations"; args=()
(0.001) SELECT "blog_post"."id", "blog_post"."title", "blog_post"."desc", "blog_post"."content", "blog_post"."html", "blog_post"."is_markdown", "blog_post"."status", "blog_post"."category_id", "blog_post"."owner_id", "blog_post"."created_time", "blog_post"."pv", "blog_post"."uv" FROM "blog_post" WHERE "blog_post"."id" = 1; args=(1,)
(0.000) SELECT "blog_category"."id", "blog_category"."name", "blog_category"."status", "blog_category"."is_nav", "blog_category"."owner_id", "blog_category"."created_time" FROM "blog_category" WHERE ("blog_category"."status" = 1 AND "blog_category"."is_nav" = 1); args=(1, True)
(0.000) SELECT "blog_category"."id", "blog_category"."name", "blog_category"."status", "blog_category"."is_nav", "blog_category"."owner_id", "blog_category"."created_time" FROM "blog_category" WHERE "blog_category"."id" = 1; args=(1,)
(0.000) SELECT "blog_category"."id", "blog_category"."name", "blog_category"."status", "blog_category"."is_nav", "blog_category"."owner_id", "blog_category"."created_time" FROM "blog_category" WHERE ("blog_category"."status" = 1 AND "blog_category"."is_nav" = 0); args=(1, False)
(0.000) SELECT "config_sidebar"."id", "config_sidebar"."title", "config_sidebar"."display_type", "config_sidebar"."content", "config_sidebar"."status", "config_sidebar"."owner_id", "config_sidebar"."created_time" FROM "config_sidebar" WHERE "config_sidebar"."status" = 1; args=(1,)
"GET /post/1/ HTTP/1.1" 200 518
(0.000) SELECT (1) AS "a" FROM "blog_post" LIMIT 1; args=()
(0.000) SELECT COUNT(*) AS "__count" FROM "blog_post"; args=()
(0.000) SELECT "blog_category"."id", "blog_category"."name", "blog_category"."status", "blog_category"."is_nav", "blog_category"."owner_id", "blog_category"."created_time" FROM "blog_category" WHERE ("blog_category"."status" = 1 AND "blog_category"."is_nav" = 1); args=(1, True)
(0.000) SELECT "blog_post"."id", "blog_post"."title", "blog_post"."desc", "blog_post"."content", "blog_post"."html", "blog_post"."is_markdown", "blog_post"."status", "blog_post"."category_id", "blog_post"."owner_id", "blog_post"."created_time", "blog_post"."pv", "blog_post"."uv" FROM "blog_post" LIMIT 1; args=()
(0.000) SELECT "blog_post"."id", "blog_post"."title", "blog_post"."desc", "blog_post"."content", "blog_post"."html", "blog_post"."is_markdown", "blog_post"."status", "blog_post"."category_id", "blog_post"."owner_id", "blog_post"."created_time", "blog_post"."pv", "blog_post"."uv" FROM "blog_post" WHERE "blog_post"."status" = 1 ORDER BY "blog_post"."pv" DESC LIMIT 10; args=(1,)
(0.000) SELECT "blog_post"."id", "blog_post"."title", "blog_post"."desc", "blog_post"."content", "blog_post"."html", "blog_post"."is_markdown", "blog_post"."status", "blog_post"."category_id", "blog_post"."owner_id", "blog_post"."created_time", "blog_post"."pv", "blog_post"."uv" FROM "blog_post" WHERE "blog_post"."status" = 1 LIMIT 10; args=(1,)
(0.000) SELECT "comment_comment"."id", "comment_comment"."target", "comment_comment"."content", "comment_comment"."nickname", "comment_comment"."website", "comment_comment"."email", "comment_comment"."status", "comment_comment"."created_time" FROM "comment_comment" WHERE "comment_comment"."status" = 1 LIMIT 10; args=(1,)
(0.000) SELECT "config_sidebar"."id", "config_sidebar"."title", "config_sidebar"."display_type", "config_sidebar"."content", "config_sidebar"."status", "config_sidebar"."owner_id", "config_sidebar"."created_time" FROM "config_sidebar" WHERE "config_sidebar"."status" = 1 LIMIT 21; args=(1,)
(0.000) SELECT "blog_category"."id", "blog_category"."name", "blog_category"."status", "blog_category"."is_nav", "blog_category"."owner_id", "blog_category"."created_time" FROM "blog_category" WHERE ("blog_category"."status" = 1 AND "blog_category"."is_nav" = 0) LIMIT 21; args=(1, False)
Exception while resolving variable 'query' in template 'blog/list.html'.
Traceback (most recent call last):
  File "C:\Python27\lib\site-packages\django\template\base.py", line 903, in _resolve_lookup
    (bit, current))  # missing attribute
VariableDoesNotExist: Failed lookup for key [query] in u"[{'False': False, 'None': None, 'True': True}, {u'csrf_token': <SimpleLazyObject: <function _get_val at 0x0000000004FC1C18>>, 'user': <SimpleLazyObject: <function <lambda> at 0x0000000004FC14A8>>, 'perms': <django.contrib.auth.context_processors.PermWrapper object at 0x0000000005068048>, 'DEFAULT_MESSAGE_LEVELS': {'DEBUG': 10, 'INFO': 20, 'WARNING': 30, 'SUCCESS': 25, 'ERROR': 40}, 'messages': <django.contrib.messages.storage.fallback.FallbackStorage object at 0x0000000004FA9DA0>, u'request': <WSGIRequest: GET '/'>}, {}, {u'paginator': <django.core.paginator.Paginator object at 0x0000000004FC0400>, u'hot_posts': <QuerySet [<Post: \u4f60\u597d>, <Post: \u5929\u5929>, <Post: 66>, <Post: 77>, <Post: 88>]>, u'object_list': <QuerySet [<Post: \u4f60\u597d>]>, u'posts': <QuerySet [<Post: \u4f60\u597d>]>, u'recently_posts': <QuerySet [<Post: \u4f60\u597d>, <Post: \u5929\u5929>, <Post: 66>, <Post: 77>, <Post: 88>]>, u'recently_comments': <QuerySet []>, u'side_bars': <QuerySet [<SideBar: SideBar object>]>, u'page_obj': <Page 1 of 5>, u'cates': <QuerySet []>, u'nav_cates': <QuerySet [<Category: \u65e5\u5e38>, <Category: yy>]>, u'is_paginated': True, u'view': <blog.views.IndexView object at 0x0000000004FA9E80>}, {'block': <Block Node: content. Contents: [<TextNode: u'\\n<ul>\\n\\n\\n\\n'>, <IfNode>, <TextNode: u'\\n\\n\\n</ul>\\n\\n\\n'>]>}]"
(0.000) SELECT "blog_category"."id", "blog_category"."name", "blog_category"."status", "blog_category"."is_nav", "blog_category"."owner_id", "blog_category"."created_time" FROM "blog_category" WHERE ("blog_category"."status" = 1 AND "blog_category"."is_nav" = 0); args=(1, False)
(0.000) SELECT "config_sidebar"."id", "config_sidebar"."title", "config_sidebar"."display_type", "config_sidebar"."content", "config_sidebar"."status", "config_sidebar"."owner_id", "config_sidebar"."created_time" FROM "config_sidebar" WHERE "config_sidebar"."status" = 1; args=(1,)
"GET / HTTP/1.1" 200 550
回帖
  • lyhabc
    lyhabc(楼主)
    2018年8月20日 18:56

    格式有问题,我贴图吧 http://the5fireblog.b0.upaiyun.com/v_the5fire/f97e82f70671ecb3b9299f1d297bfb9f.png

    f http://the5fireblog.b0.upaiyun.com/v_the5fire/edbfbc94f61338263210f355b9d203fd.png

  • the5fire
    2018年8月20日 19:00

    因为你的logger django 的handlers用的是file啊,并且级别是DEBUG。