Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to log from Python Luigi

I am trying to build a strategy to log from Luigi in such a way that there is a configurable list of outputs including stdout and a custom list of files. I would like to be able to set the logging level at runtime. Our system uses Luigi to call spark from Jenkins. Thank you in advance.

like image 723
sakurashinken Avatar asked Jun 16 '16 18:06

sakurashinken


People also ask

How do you run Luigi in Python?

By default, Luigi tasks run using the Luigi scheduler. To run one of your previous tasks using the Luigi scheduler omit the --local-scheduler argument from the command. Re-run the task from Step 3 using the following command: python -m luigi --module word-frequency GetTopBooks.

What is Python log debugging?

logging.debug() Diagnose problems, show detailed information. The logging module sets the default level at WARNING , so WARNING , ERROR , and CRITICAL will all be logged by default.


1 Answers

Inside any of the Task class methods, you can do:

class Agg(luigi.Task):
  _date = luigi.DateParameter()

  def output(self):
    return luigi.LocalTarget("file_%.txt" % self._date)

  def run(self):
    # Use the luigi-interface to log to console
    logger = logging.getLogger('luigi-interface')
    logger.info("Running --> Agg.Task")
like image 74
Evhz Avatar answered Sep 28 '22 01:09

Evhz