简体   繁体   English

Django-如何确定django正在记录哪个模块?

[英]Django - How do I figure out what module is being logged by django?

I want to add a global custom formatter to all django modules so I can ingest a consistent log file with Elasticsearch. 我想向所有django模块添加一个全局自定义格式化程序,以便可以使用Elasticsearch接收一致的日志文件。 How do I figure out what django modules are logging what so I can change all their formatters? 我如何确定哪些django模块正在记录什么,以便可以更改其所有格式化程序?

在此处输入图片说明

Here is my log config in settings.py . 这是我在settings.py日志配置。 Using django 2.0. 使用django 2.0。

# NOTE: Copied from DEFAULT_LOGGING and added custom format
# from django.utils.log import DEFAULT_LOGGING

LOGGING = {
    'version': 1,
    'disable_existing_loggers': False,
    'filters': {
        'require_debug_false': {'()': 'django.utils.log.RequireDebugFalse'},
        'require_debug_true': {'()': 'django.utils.log.RequireDebugTrue'}},
    'formatters': {
        'django.server': {
            '()': 'django.utils.log.ServerFormatter',
            'format': '[%(asctime)s] %(levelname)s [%(name)s.%(funcName)s:%(lineno)d] %(module)s %(message)s',
            'datefmt': '%Y-%m-%d %H:%M:%S'}},
    'handlers': {
        'console': {
            'class': 'logging.StreamHandler',
            'filters': ['require_debug_true'],
            'level': 'INFO'},
        'django.server': {
            'class': 'logging.StreamHandler',
            'formatter': 'django.server',
            'level': 'INFO'},
        'mail_admins': {
            'class': 'django.utils.log.AdminEmailHandler',
            'filters': ['require_debug_false'],
            'level': 'ERROR'}},
    'loggers': {
        'api': {
            'handlers': ['django.server'],
            'level': 'INFO',
            'propagate': False},
        'django': {
            'handlers': ['django.server', 'mail_admins'],
            'level': 'INFO'},
        'django.server': {
            'handlers': ['django.server'],
            'level': 'INFO',
            'propagate': False}},
}

Add your unique tag in the formatting string and then search for this keywords in your ELK. 在格式字符串中添加唯一标签,然后在ELK中搜索此关键字。

Like : 喜欢 :

%(asctime)s] %(levelname)s [%(name)s.%(funcName)s:%(lineno)d] MYMODULE [%(module)s ] %(message)s' %(asctime)s]%(levelname)s [%(name)s。%(funcName)s:%(lineno)d] MYMODULE [%(module)s]%(message)s'

In above case I will search for MYMODULE tags in the log. 在上述情况下,我将在日志中搜索MYMODULE标签。

暂无
暂无

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

相关问题 如何确定我的 Django 应用程序需要什么 AWS RDS 实例? - How do I figure out what AWS RDS instance does my Django application need? 如何在不注销django的情况下突破框架? - How to break out of a frame without being logged out in django? 在Django中,当我不知道在哪里设置跟踪时,如何触发pdb找出导致404错误的原因? - In Django, how do I trigger pdb to figure out what's causing a 404 when I don't know where to set a trace? 当我将Django应用程序从一个系统复制到另一个系统时,如何确定要安装哪些依赖项? - How do I figure out what dependencies to install when I copy my Django app from one system to another? 我如何在django中设置/获取cookie,如果用户已登录并注销,该cookie可用 - How do I set/get a cookie in django that is available if user is logged in AND logged out 如何在 Django 中找出 NoReverseMatch - How to figure out NoReverseMatch at / in Django Django / Python API-如何确定方法期望接收的对象类? - Django/Python API - how can I figure out what class of object a method is expecting to receive? 如何让 Django 根据 Z293C9EA246FF978986F 请求中的“主机”header 确定要使用哪个站点 object? - How do I make Django figure out which Site object to use based on “Host” header in the HTTP request? 我登出后如何在Django中呼叫预设的首页网址 - How to Call default home url in django when i logged out Django用户退出了 - Django users logged out
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM