AI4Finance-Foundation / FinRL-Meta

FinRL­-Meta: Dynamic datasets and market environments for FinRL.
https://ai4finance.org
MIT License
1.2k stars 560 forks source link

remove all the print() statements and use some form of logging instead #196

Open chennnuo opened 2 years ago

chennnuo commented 2 years ago

The following functions have been modified:

zhumingpassional commented 2 years ago

the following can be written a function? logger = logging.getLogger() logger.setLevel("DEBUG") file_handler = logging.FileHandler("./log.txt", mode="a", encoding="utf-8") file_handler.setLevel("DEBUG") file_handler.setFormatter( logging.Formatter(fmt="%(lineno)s---%(asctime)s---%(message)s") ) logger.addHandler(file_handler)

zhumingpassional commented 2 years ago

have you revised all print() to logging?

chennnuo commented 2 years ago

have you revised all print() to logging?

I have checked all run files at present, and I will continue to check other files in the package later.

chennnuo commented 2 years ago

Thanks for your advice. I'm doing this, I have a question, which folder would be more appropriate for the "log" function to be placed? meta? Or create a new folder, like utils?

zhumingpassional commented 2 years ago

i prefer creating a log folder.

hawkeye-bot commented 2 years ago

Good step to replace all the print functions by logging-statements!

May I suggest 2 changes to the logging stuff? 1) place the log initialization in a generic function somewhere as @zhumingpassional suggests 2) load log configuration from a logging file (example code below). This allows for easy modification to the log setup, without having to modify the code itself. Just a suggestion :)

with open(args.logging_config_file, 'rt') as file: logging_config = yaml.safe_load(file.read()) try: logging_config['handlers']['file_handler']['filename'] = args.logfile except Exception: pass # just ignore it logging.config.dictConfig(logging_config)

zhumingpassional commented 2 years ago

@hoeckxer good suggestions. thanks. glad to work with you.

@chennnuo pls revise it as the above suggestions. thanks.

eyast commented 2 years ago

Hey guys how about using a log Decorator?

https://ankitbko.github.io/blog/2021/04/logging-in-python/

chennnuo commented 2 years ago

Thank you very much for everyone's suggestions, I will take your suggestions seriously to revise and improve!

zhumingpassional commented 2 years ago

Hey guys how about using a log Decorator?

https://ankitbko.github.io/blog/2021/04/logging-in-python/

@eyast impressive idea.

@chennnuo you do not need to close it. you can revise PR locally and push it again.

chennnuo commented 2 years ago

Oh sorry, I'll reopen it right away, revise PR locally and push it again as soon as I'm done modifying and testing.

YangletLiu commented 2 years ago

@chennnuo Just to check that this is fixed in the PR https://github.com/AI4Finance-Foundation/FinRL-Meta/pull/195 right? Do we need a further operation?

chennnuo commented 2 years ago

@XiaoYangLiu-FinRL Sorry, I haven't finished fixing it yet, I'll fix it soon and let you know.

YangletLiu commented 2 years ago

@chennnuo No problem. Remember to use the most updated branch, to avoid conflict. Thanks.

chennnuo commented 2 years ago

@XiaoYangLiu-FinRL Ok thanks for the heads up, I'll keep an eye on that.