Skip to content

configure logger with dictConfig#97

Open
gretzteam wants to merge 1 commit intothemperek:masterfrom
gretzteam:logconfig
Open

configure logger with dictConfig#97
gretzteam wants to merge 1 commit intothemperek:masterfrom
gretzteam:logconfig

Conversation

@gretzteam
Copy link
Contributor

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.

@themperek
Copy link
Owner

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

@gretzteam
Copy link
Contributor Author

gretzteam commented Sep 17, 2020

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)

@themperek themperek force-pushed the master branch 2 times, most recently from d52e608 to 9bd8e5a Compare January 2, 2021 12:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants