最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

python 3.x - Django logger only logging to console from celery worker process - Stack Overflow

programmeradmin1浏览0评论

I have a following logging config:

"root": {
    "level": "ERROR",
    "handlers": ["console", "server_file"],
},
"handlers": {
    "celery_file": {
        "class": "logging.handlers.RotatingFileHandler",
        "level": "DEBUG",
        "filename": os.path.join(ROOT_LOGS_DIR, "celery", "celery.log"),
        "formatter": "standard",
        "maxBytes": 1024 * 1024 * 50,  # 50 MB
        "backupCount": 30,
    },
    "server_file": {
        "class": "logging.handlers.RotatingFileHandler",
        "level": "DEBUG",
        "filename": os.path.join(ROOT_LOGS_DIR, "server.log"),
        "formatter": "standard",
        "maxBytes": 1024 * 1024 * 50,  # 50 MB
        "backupCount": 30,
    },
"loggers": {
    # '': {'handlers': ["root"], "level": "DEBUG", "propagate": True, },
    'django': {'handlers': ['django'], 'level': 'DEBUG', 'propagate': False, },        
    "celery": {
        "handlers": ["celery_file"],
        "level": "INFO",
        "propagate": True,
    },

From celery task,

log = logging.getLogger("celery.inbound_outbound_jobs")
log.error("Hello, World!") # this won't be written to files. Only Console.

I run this task using celery-beat and worker.

celery -A log_project beat --loglevel=info
celery -A log_project worker --loglevel=info

But this is not writing logs to server.log and celery.log.

Only console logging is happening.

When running this task directly from django server and not as celery worker process, this is working in all celery.log, server.log and console.

Can anyone help understand this?

发布评论

评论列表(0)

  1. 暂无评论