This document describes the current stable version of Celery (5.6). For development docs, go here.

# `celery.utils.log`

Logging utilities.

class celery.utils.log.ColorFormatter(fmt=None, use_color=True)

  Logging formatter that adds colors based on severity.

  COLORS = {'black': <bound method colored.black of ''>, 'blue': <bound method colored.blue of ''>, 'cyan': <bound method colored.cyan of ''>, 'green': <bound method colored.green of ''>, 'magenta': <bound method colored.magenta of ''>, 'red': <bound method colored.red of ''>, 'white': <bound method colored.white of ''>, 'yellow': <bound method colored.yellow of ''>}

    Loglevel -> Color mapping.

  colors = {'CRITICAL': <bound method colored.magenta of ''>, 'DEBUG': <bound method colored.blue of ''>, 'ERROR': <bound method colored.red of ''>, 'WARNING': <bound method colored.yellow of ''>}
  format(record)

    Format the specified record as text.

    The record’s attribute dictionary is used as the operand to a string formatting operation which yields the returned string. Before formatting the dictionary, a couple of preparatory steps are carried out. The message attribute of the record is computed using LogRecord.getMessage(). If the formatting string uses the time (as determined by a call to usesTime(), formatTime() is called to format the event time. If there is exception information, it is formatted using formatException() and appended to the message.

  formatException(ei)

    Format and return the specified exception information as a string.

    This default implementation just uses traceback.print_exception()

class celery.utils.log.LoggingProxy(logger, loglevel=None)

  Forward file object to `logging.Logger` instance.

  Parameters:

    - logger (Logger) – Logger instance to forward to.

    - loglevel (int, str) – Log level to use when logging messages.

  close()
  closed = False
  flush()
  isatty()

    Here for file support.

  loglevel = 40
  mode = 'w'
  name = None
  write(data: AnyStr) → int

    Write message to logging object.

  writelines(sequence: Sequence[str]) → None

    Write list of strings to file.

    The sequence can be any iterable object producing strings. This is equivalent to calling `write()` for each string.

celery.utils.log.get_logger(name)

  Get logger by name.

celery.utils.log.get_multiprocessing_logger()

  Return the multiprocessing logger.

celery.utils.log.get_task_logger(name)

  Get logger for task module by name.

celery.utils.log.in_sighandler()

  Context that records that we are in a signal handler.

celery.utils.log.mlevel(level)

  Convert level name/int to log level.

celery.utils.log.reset_multiprocessing_logger()

  Reset multiprocessing logging setup.

celery.utils.log.set_in_sighandler(value)

  Set flag signifying that we’re inside a signal handler.