为什么Logging在django网站上不工作? [英] Why Logging is not working on django website?

查看:324
本文介绍了为什么Logging在django网站上不工作?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我试过的
在我的view.py文件中,

This is what i tried . In my view.py file ,

import logging
logger = logging.getLogger("mylog")
logging.basicConfig(format='%(name)s:%(levelname)s:%(message)s',level=logging.INFO,datefmt='%d/%m/%y %I:%M:%S')

然后在一个函数内,

logger.debug("this is an error")
logger.warning("This is a warning")
print "This is a test line '

我没有碰到settings.py文件几乎相同。 / p>

I have not touched the settings.py file .its pretty much the same.

LOGGING = {

    'version': 1,

    'disable_existing_loggers': False,

    'handlers': {

        'mail_admins': {

            'level': 'ERROR',

            'class': 'django.utils.log.AdminEmailHandler'

        }

    },

    'loggers': {

        'django.request': {

            'handlers': ['mail_admins'],

            'level': 'ERROR',

            'propagate': True,

        },

    }

当我运行服务器并调用该函数时,没有任何反应。没有错误,没有任何东西。

When i run the server , and call the function , nothing happens . no error , nothing .

我只想在控制台上看到日志行。

I just want to see a log line on the console .

推荐答案

尝试将其添加到处理程序中:

Try adding this to handlers:

'console':{
            'level':'DEBUG',
            'class':'logging.StreamHandler',
            'formatter': 'simple'
           }

和记录员:

    'django': {
        'handlers':['console'],
        'propagate': True,
        'level':'INFO',
    },

日志级别可能相同或不同 - 实际上,处理程序定义它将记录的最低级别,而记录器定义它将发送到处理程序的最低级别。如果一个处理程序被两个或多个记录器使用 - 理想情况下应该是两个记录器的最低级别。

The log level could be the same or different - In fact the handler defines the minimum level it will log, while the logger defines the minimum level it will send to handler. If one handler is used by two or more loggers - it should ideally has the lowest level from both loggers.

编辑:感谢@jpic指向记录器部分。

EDIT: Thanks to @jpic for pointing the loggers section.

这篇关于为什么Logging在django网站上不工作?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆