简体   繁体   English

Django + heroku:显示django日志,app日志不显示

[英]Django+heroku: django logs appear, app logs don't

I read all the StackOverflow answers, all the blog posts on the subject, and tried everything twice, but I still can't get my Django app's log messsages to appear in the heroku log (Django's own messages do appear). 我阅读了所有StackOverflow答案,关于这个主题的所有博客文章,并尝试了两次,但我仍然无法让我的Django应用程序的日志消息出现在heroku日志中(Django自己的消息确实出现)。

Can anyone please paste a full LOGGING config that works in heroku? 任何人都可以粘贴一个在heroku中工作的完整LOGGING配置吗?

# views.py
import logging
logger = logging.getLogger(__name__)

def a_view(request):
    # ...
    logger.exception('error finding file')
    # ...

with: 有:

# settings.py
LOGGING = {
    "version": 1,
    "disable_existing_loggers": False,
    'formatters': {
        'simple': {
            'format': '%(levelname)s [%(name)s:%(lineno)s] %(message)s'
        },
    },
    'handlers': {
        'console': {
            'level': 'INFO',
            'class': 'logging.StreamHandler',
            'formatter': 'simple',
            "stream": sys.stdout
        },
    },
    "loggers": {
        "root": {
            "handlers": ["console"],
        },
        # last try :(
        "myapp": {
            "handlers": ["console"],
        },
        "django": {
            "handlers": ["console"],
        }
    }
}

Here is a configuration that worked for me (OP): 这是一个适合我的配置(OP):

LOGGING = {
    "version": 1,
    "disable_existing_loggers": False,
    'formatters': {
        'simple': {
            'format': '%(levelname)s [%(name)s:%(lineno)s] %(message)s'
        },
    },
    'handlers': {
        'console': {
            'level': 'INFO',
            'class': 'logging.StreamHandler',
            'formatter': 'simple',
            "stream": sys.stdout
        },
    },
    "loggers": {
        "": {
            "handlers": ["console"],
            'level': 'INFO',
        },
        "django": {
            "handlers": ["console"],
            'level': 'INFO',
        }
    }
}

The modification that made the difference is changing the level of all loggers, but before that I changed "root" to "" , so that might have been needed too. 产生差异的修改是改变所有记录器的级别,但在此之前我将"root"更改为"" ,因此可能也需要。

edit: removed "myapp" logger as it is captured by "" logger, resolved my double logging issue. 编辑:删除“myapp”记录器,因为它被“”记录器捕获,解决了我的双重记录问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM