From b39619bb3e318148bbfc47e9677f953ea2257355 Mon Sep 17 00:00:00 2001 From: Omer Yampel Date: Wed, 28 Jun 2017 09:56:12 -0400 Subject: [PATCH 1/2] Celery task logging in place of blueprints When inside a celery task, this allows you to use the task name rather than a blueprint --- flask_logging_extras/__init__.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/flask_logging_extras/__init__.py b/flask_logging_extras/__init__.py index 44a3d45..c432a02 100644 --- a/flask_logging_extras/__init__.py +++ b/flask_logging_extras/__init__.py @@ -32,6 +32,11 @@ no value is present in the message record. import logging +try: + from celery import current_task: +except ImportError: + current_task = None + from flask import has_request_context, request __version_info__ = ('0', '0', '1') @@ -134,7 +139,9 @@ class FlaskExtraLogger(logging.getLoggerClass()): # If we were asked to log the blueprint name, add it to the extra list if self._blueprint_var is not None: - if has_request_context(): + if current_task: + kwargs['extra'][self._blueprint_var] = current_task.name + elif has_request_context(): kwargs['extra'][self._blueprint_var] = request.blueprint or self._blueprint_app else: kwargs['extra'][self._blueprint_var] = self._blueprint_norequest From fad4ef5b364092eacf1fa2b1906cb5691e20f16c Mon Sep 17 00:00:00 2001 From: Omer Yampel Date: Fri, 30 Jun 2017 23:56:11 -0400 Subject: [PATCH 2/2] Update .travis.yml Adds celery into pip install for travis --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 9b03293..b924f3b 100644 --- a/.travis.yml +++ b/.travis.yml @@ -9,7 +9,7 @@ env: - TOXENV=py35 install: - pip install -U pip - - pip install -U Flask tox coverage codecov + - pip install -U Flask tox coverage codecov celery script: - tox after_success: