cocotb-test icon indicating copy to clipboard operation
cocotb-test copied to clipboard

configure logger with dictConfig

Open gretzteam opened this issue 4 years ago • 2 comments

Allow the python logs to go to a file and console at the same time.

Used the logging.config.dictConfig() to configure the loggers with two handlers: ->console output using logging.StreamHandler ->file output using logging.FileHandler Independent configs can be selected for each handlers.

The ansi characters are stripped by setting the formatter of file output handler to NoAnsiFormatter.

More handlers and settings can easily be added to the dictConfig.

gretzteam avatar Sep 17 '20 14:09 gretzteam

Would not be better to be done by the user in the command line/test code?

themperek avatar Sep 17 '20 15:09 themperek

Having hooks to control from the calling test scrip would be good. I'm not sure what the best way is. But right now the log file isn't created anywhere. I feel it should happen by default because that is what most user want. For example the cocotb makefiles do output the entire console content to a file.

A more direct alternative only adding a file handler output would be something like:

        self.logger = logging.getLogger("cocotb")
        self.logger.setLevel(logging.INFO)
        logging.basicConfig(format="%(levelname)s %(name)s: %(message)s", handlers=[logging.StreamHandler()])
        fileh = logging.FileHandler(self.sim_dir + "/sim.log")
        formatter = NoAnsiFormatter("%(message)s")
        fileh.setFormatter(formatter)
        self.logger.addHandler(fileh)

gretzteam avatar Sep 17 '20 17:09 gretzteam