Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

configure logger with dictConfig #97

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

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