d6t/d6tflow

Configure logging

astenuz opened this issue · 2 comments

Hi, I would like your help figuring out how to configure the logging, so an example like this outputs the log message in the console. The only mention of logging configuration in the docs is to change the logging level.

import d6tflow
import logging

log = logging.getLogger()


class TaskTest(d6tflow.tasks.TaskCache):

    def run(self):
        log.info("Hello!")
        self.save({"output": 0})


d6tflow.run(TaskTest())

Assuming you already have configured a logger in your main this should work
Also I commented some steps in case you don't

Be aware this uses the luigi/d6tflow logger so whatever you log will be within other luigi logs

import logging
class TaskTest(d6tflow.tasks.TaskCache):
    def run(self):
        log = logging.getLogger() #->  having already configured logger
        #logging.basicConfig(level=logging.DEBUG) #without logger configured
        #log = logging.getLogger() 
        log.info("Hello!")
        self.save({"output": 0})
d6tflow.run(TaskTest())

Yes just add these two lines to your code and you will see the logging output.

import sys
logging.basicConfig(stream=sys.stdout, level=logging.INFO)

Note that we just made some changes to reduce the luigi logging output which most users considered excessive. See https://d6tflow.readthedocs.io/en/latest/run.html#hiding-execution-output

For your example, you will see:

INFO:luigi:logging configured by default settings
INFO:root:Hello!