Преглед изворни кода

Make id, name always accessible from logging.Formatter via extra (#3994)

* Make id, name always accessible from Formatter via extra

* define info with docstring

* use the same name to minimize the change
* clarify the reason for passing 'extra'

* Specific version for pydocstyle

* Add myself to the contributors list
Yoichi NAKAYAMA пре 7 година
родитељ
комит
fd8b52e3c8
2 измењених фајлова са 9 додато и 1 уклоњено
  1. 1 0
      CONTRIBUTORS.txt
  2. 8 1
      celery/app/trace.py

+ 1 - 0
CONTRIBUTORS.txt

@@ -236,6 +236,7 @@ Jianjian Yu, 2017/04/09
 Brian May, 2017/04/10
 Dmytro Petruk, 2017/04/12
 Joey Wilhelm, 2017/04/12
+Yoichi Nakayama, 2017/04/25
 Simon Schmidt, 2017/05/19
 Anthony Lukach, 2017/05/23
 Samuel Dion-Girardeau, 2017/05/29

+ 8 - 1
celery/app/trace.py

@@ -49,7 +49,6 @@ __all__ = [
 ]
 
 logger = get_logger(__name__)
-info = logger.info
 
 #: Format string used to log task success.
 LOG_SUCCESS = """\
@@ -116,6 +115,14 @@ _patched = {}
 trace_ok_t = namedtuple('trace_ok_t', ('retval', 'info', 'runtime', 'retstr'))
 
 
+def info(fmt, context):
+    """Log 'fmt % context' with severity 'INFO'.
+
+    'context' is also passed in extra with key 'data' for custom handlers.
+    """
+    logger.info(fmt, context, extra={'data': context})
+
+
 def task_has_custom(task, attr):
     """Return true if the task overrides ``attr``."""
     return mro_lookup(task.__class__, attr, stop={BaseTask, object},