簡體   English   中英

Django - 突然登錄到(運行服務器)控制台

[英]Django - suddenly logging to (runserver) console

我不明白為什么Django開始登錄控制台。 當我運行django服務器(在PyCharm )時,同一個控制台中有日志條目。

我最近安裝了我的pysendpulse分支,但這可能是巧合。

INFO     [2019-04-08 00:59:05,331]  Initialization SendPulse REST API Class
DEBUG    [2019-04-08 00:59:05,331]  Try to get security token from 'MEMCACHED'
DEBUG    [2019-04-08 00:59:05,331]  Got: 'some string'
INFO     [2019-04-08 00:59:05,775]  Initialization SendPulse REST API Class
DEBUG    [2019-04-08 00:59:05,775]  Try to get security token from 'MEMCACHED'
DEBUG    [2019-04-08 00:59:05,775]  Got: 'some string'
Performing system checks...

System check identified no issues (0 silenced).
DEBUG    [2019-04-08 00:59:06,025]  (0.001) 
            SELECT c.relname, c.relkind
            FROM pg_catalog.pg_class c
            LEFT JOIN pg_catalog.pg_namespace n ON n.oid = c.relnamespace
            WHERE c.relkind IN ('r', 'v')
                AND n.nspname NOT IN ('pg_catalog', 'pg_toast')
                AND pg_catalog.pg_table_is_visible(c.oid); args=None
DEBUG    [2019-04-08 00:59:06,026]  (0.000) SELECT "django_migrations"."app", "django_migrations"."name" FROM "django_migrations"; args=()
April 08, 2019 - 00:59:06
Django version 2.1.7, using settings 'p.settings'
Starting development server at http://127.0.0.1:8000/
Quit the server with CONTROL-C.

例如,第一行是從這里記錄的:

logging.info("Initialization SendPulse REST API Class")

設置.LOGGING

LOGGING = {
    'version': 1,
    'disable_existing_loggers': False,
    'formatters': {
        'verbose': {
            'format': '{asctime} {levelname} {module} {message}',
            'style': '{',
        },
    },
    'handlers': {
        'local_file_debug': {
            'level': 'DEBUG',
            'class': 'logging.handlers.RotatingFileHandler',
            'filename': os.path.join(LOG_PATH, 'django_debug.log'),
            'maxBytes': DEFAULT_LOG_SIZE,
            'backupCount': 0,
        },
        'local_file': {
            'level': 'WARNING',
            'class': 'logging.handlers.RotatingFileHandler',
            'filename': os.path.join(LOG_PATH, 'django.log'),
            'maxBytes': DEFAULT_LOG_SIZE,
            'backupCount': 0,
        },
        'pipedrive': {
            'level': 'DEBUG' if DEBUG else 'INFO',
            'class': 'logging.handlers.RotatingFileHandler',
            'filename': os.path.join(LOG_PATH, 'pipedrive.log'),
            'formatter': 'verbose',
            'maxBytes': DEFAULT_LOG_SIZE,
            'backupCount': 0,
        },
    },
    'loggers': {
        'django': {
            'handlers': ['local_file_debug' if DEBUG else 'local_file'],
            'level': 'DEBUG',
            'propagate': True,
        },
        'pipedrive': {
            'handlers': ['pipedrive'],
            'level': 'DEBUG',
        },
    },
}

你知道問題出在哪里嗎?

編輯

shell_plus

打印(日志記錄.root)

<RootLogger root (DEBUG)>

打印(logging.Logger.manager.loggerDict)

{'amqp': <Logger amqp (DEBUG)>, 'kombu.connection': <Logger kombu.connection (DEBUG)>, 'kombu': <logging.PlaceHolder object at 0x7f32045565c0>, 'celery': <Logger celery (DEBUG)>, 'celery.task': <Logger celery.task (DEBUG)>, 'celery.worker': <Logger celery.worker (DEBUG)>, 'kombu.common': <Logger kombu.common (DEBUG)>, 'celery.utils.dispatch.signal': <Logger celery.utils.dispatch.signal (DEBUG)>, 'celery.utils.dispatch': <logging.PlaceHolder object at 0x7f3203609898>, 'celery.utils': <logging.PlaceHolder object at 0x7f3203609978>, 'celery.app.builtins': <Logger celery.app.builtins (DEBUG)>, 'celery.app': <logging.PlaceHolder object at 0x7f32036e6c88>, 'celery.app.base': <Logger celery.app.base (DEBUG)>, 'django.template': <Logger django.template (DEBUG)>, 'django': <Logger django (DEBUG)>, 'concurrent.futures': <Logger concurrent.futures (DEBUG)>, 'concurrent': <logging.PlaceHolder object at 0x7f3203267940>, 'asyncio': <Logger asyncio (DEBUG)>, 'django.db.backends': <Logger django.db.backends (DEBUG)>, 'django.db': <logging.PlaceHolder object at 0x7f3202855668>, 'django.request': <Logger django.request (DEBUG)>, 'django.server': <Logger django.server (DEBUG)>, 'pipedrive': <Logger pipedrive (DEBUG)>, 'django.security.csrf': <Logger django.security.csrf (DEBUG)>, 'django.security': <logging.PlaceHolder object at 0x7f32025823c8>, 'django.db.backends.schema': <Logger django.db.backends.schema (DEBUG)>, 'urllib3.util.retry': <Logger urllib3.util.retry (DEBUG)>, 'urllib3.util': <logging.PlaceHolder object at 0x7f31feafb4e0>, 'urllib3': <Logger urllib3 (DEBUG)>, 'urllib3.connection': <Logger urllib3.connection (DEBUG)>, 'urllib3.response': <Logger urllib3.response (DEBUG)>, 'urllib3.connectionpool': <Logger urllib3.connectionpool (DEBUG)>, 'urllib3.poolmanager': <Logger urllib3.poolmanager (DEBUG)>, 'requests': <Logger requests (DEBUG)>, 'superfakura.api': <Logger superfakura.api (DEBUG)>, 'superfakura': <logging.PlaceHolder object at 0x7f31fe527208>, 'p.apps.apis.superfaktura.utils': <Logger p.apps.apis.superfaktura.utils (DEBUG)>, 'p.apps.apis.superfaktura': <logging.PlaceHolder object at 0x7f31fe51c7b8>, 'p.apps.apis': <logging.PlaceHolder object at 0x7f31fe51c860>, 'p.apps': <logging.PlaceHolder object at 0x7f31fe527470>, 'p': <logging.PlaceHolder object at 0x7f31fe527588>, 'p.apps.apis.superfaktura.models': <Logger p.apps.apis.superfaktura.models (DEBUG)>, 'django_bootstrap_breadcrumbs.templatetags.django_bootstrap_breadcrumbs': <Logger django_bootstrap_breadcrumbs.templatetags.django_bootstrap_breadcrumbs (DEBUG)>, 'django_bootstrap_breadcrumbs.templatetags': <logging.PlaceHolder object at 0x7f31fdece2b0>, 'django_bootstrap_breadcrumbs': <logging.PlaceHolder object at 0x7f31fdece2e8>, 'PIL.Image': <Logger PIL.Image (DEBUG)>, 'PIL': <logging.PlaceHolder object at 0x7f31fdea29e8>, 'prompt_toolkit': <Logger prompt_toolkit (DEBUG)>, 'parso.python.diff': <Logger parso.python.diff (DEBUG)>, 'parso.python': <logging.PlaceHolder object at 0x7f31fc597668>, 'parso': <logging.PlaceHolder object at 0x7f31fc597be0>, 'parso.cache': <Logger parso.cache (DEBUG)>, 'TerminalIPythonApp': <Logger TerminalIPythonApp (WARNING)>}

我最近安裝了我的pysendpulse分支,但這可能是巧合。

根據您分叉它的方式/地點,這並非巧合。
原始pysendpulse在包的__init__.py調用logging.basicConfig

logging.basicConfig(format='%(levelname)-8s [%(asctime)s]  %(message)s', level=logging.DEBUG)

basicConfig的目的是設置...

... 通過使用默認Formatter創建StreamHandler並將其添加到根記錄器中,日志系統的基本配置。

這是在這里完成的。

由於您將django記錄器配置為傳播(這是默認設置)

'propagate': True,

日志記錄不僅由您的專用記錄器處理,而且還會沿祖先鏈向上發送,最終到達root記錄器。

不導入pysendpulseroot記錄器沒有附加處理程序並設置為默認級別WARNING 日志記錄“丟失”(在root記錄器級別)。
但是在pysendpulselogging.basicConfig的調用pysendpulse StreamHandler附加到您的root記錄器並將其設置為級別DEBUG ,因此您會在控制台上看到消息。

至於解決方案,您可以在django記錄器上禁用傳播

'propagate': False,

root記錄器中刪除StreamHandler

logging.getLogger().removeHandler(logging.getLogger().handlers[0])

或者,由於您顯然分叉了pysendpulse ,請考慮從__init__.py模塊中刪除logging.basicConfig調用。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM