如何在 Django 调试工具栏中使用日志记录? [英] How do I use Logging in the Django Debug Toolbar?

查看:29
本文介绍了如何在 Django 调试工具栏中使用日志记录?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在我的 django 应用程序中在视图函数的不同点输出调试消息.django-debug-toolbar 的文档说它使用 python 日志记录中的构建,但我找不到更多信息.我真的不想登录到文件,而是登录到工具栏上的信息窗格.这是如何工作的?

I would like to output debug messages in my django app at different points in a view function. The docs for the django-debug-toolbar say it uses the build in python logging but I can't find any more information then that. I don't really want to log to a file but to the info pane on the toolbar. How does this work?

推荐答案

您只需使用 logging 模块 方法和 DjDT 将拦截并在日志面板中显示它们.

You just use the logging module methods and DjDT will intercept and display them in the Logging Panel.

import logging

logging.debug('Debug Message')

if some_error:
   logging.error('Error Message')

这篇关于如何在 Django 调试工具栏中使用日志记录?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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