Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/333.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 无法将stdout、stderr重定向到芹菜中的另一个记录器_Python_Celery - Fatal编程技术网

Python 无法将stdout、stderr重定向到芹菜中的另一个记录器

Python 无法将stdout、stderr重定向到芹菜中的另一个记录器,python,celery,Python,Celery,无法将标准输出重定向到芹菜中的另一个记录器,我已使用特殊处理程序为芹菜创建了特殊记录器对象。我想捕获执行任务时发生的所有异常。我在芹菜中添加了设置日志信号的处理程序,以安装我自己的记录器: import sys import logging.config from pika.adapters import BlockingConnection from pika.connection import ConnectionParameters from pika import BasicPrope

无法将标准输出重定向到芹菜中的另一个记录器,我已使用特殊处理程序为芹菜创建了特殊记录器对象。我想捕获执行任务时发生的所有异常。我在芹菜中添加了设置日志信号的处理程序,以安装我自己的记录器:

import sys
import logging.config

from pika.adapters import BlockingConnection
from pika.connection import ConnectionParameters
from pika import BasicProperties

from celery.signals import setup_logging, after_setup_logger


class RabbitMqHandler(logging.Handler):
    '''
    Special logging handler which stores log messages in RabbitMq server
    It can used for async delivering message to clients
    '''

    HOST = 'localhost'
    QUEUE = 'hermes.standard'

    def emit(self, record):
        con = BlockingConnection(ConnectionParameters(self.HOST))
        # Open the channel
        channel = con.channel()

        # Declare the queue
        channel.queue_declare(queue=self.QUEUE, durable=True,
                              exclusive=False, auto_delete=False)

        channel.basic_publish(exchange='', routing_key=self.QUEUE, body=self.format(record)) #','.join(dir(record)))
        con.close()


LOGGING = {
    'version': 1,
    'disable_existing_loggers': True,
    'formatters': {
        'verbose': {
            'format': '%(levelname)s %(asctime)s %(module)s %(process)d %(thread)d %(message)s'
        },
        'simple': {
            'format': '%(levelname)s %(message)s'
        },
        'timed': {
            'format': '[%(asctime)s: %(levelname)s] %(message)s'
        },
    },
    'handlers': {
        'null': {
            'level':'DEBUG',
            'class':'django.utils.log.NullHandler',
        },
        'console':{
            'level':'DEBUG',
            'class':'logging.StreamHandler',
            'formatter': 'timed'
        },
        'rabbit': {
            'level': 'INFO',
            'class': 'logconfig.RabbitMqHandler',
            'formatter': 'timed'
        },
        'celery': {
            'level': 'ERROR',
            'class': 'logging.FileHandler',
            'filename': '1.log',
            'formatter': 'timed',
            }
    },
    'loggers': {
        'celery': {
            'handlers': ['celery'],
            'level': 'INFO',
        },
        'hermes': {
            'handlers': ['console', 'rabbit'],
            'level': 'INFO',
        }
    }
}

from celery.log import LoggingProxy

@setup_logging.connect
def setup_logconfig(**kwargs):
    logging.config.dictConfig(LOGGING)
    #return logging.getLogger('hermes')
我自己的名为“hermes”的记录器工作正常,但所有异常都发生在catch standard Cellery的记录器name=Cellery上。我试着用设置来超越:

芹菜\u重定向\u STDOUTS=False


但它也不起作用。所有例外情况都属于标准芹菜记录器

嗨,四年后你找到解决这个问题的办法了吗:-?