FinRL-Meta icon indicating copy to clipboard operation
FinRL-Meta copied to clipboard

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

Open chennnuo opened this issue 2 years ago • 15 comments

The following functions have been modified:

  • plot.py
  • test.py
  • train.py
  • tutorials/1-Introduction/China_A_share_market_tushare.py
  • tutorials/2-Advance/Crypto_Feature_Importance.py
  • tutorials/2-Advance/FinRL_PortfolioAllocation_Explainable_DRL.py
  • tutorials/2-Advance/execution_optimizing.py
  • tutorials/2-Advance/nas100_gpu_podracer.py
  • tutorials/2-Advance/stock_jq.py

chennnuo avatar Jul 11 '22 16:07 chennnuo

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 avatar Jul 12 '22 01:07 zhumingpassional

have you revised all print() to logging?

zhumingpassional avatar Jul 12 '22 06:07 zhumingpassional

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 avatar Jul 12 '22 06:07 chennnuo

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?

chennnuo avatar Jul 12 '22 06:07 chennnuo

i prefer creating a log folder.

zhumingpassional avatar Jul 13 '22 06:07 zhumingpassional

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)

hawkeye-bot avatar Jul 13 '22 17:07 hawkeye-bot

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

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

zhumingpassional avatar Jul 14 '22 00:07 zhumingpassional

Hey guys how about using a log Decorator?

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

eyast avatar Jul 14 '22 07:07 eyast

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

chennnuo avatar Jul 14 '22 07:07 chennnuo

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.

zhumingpassional avatar Jul 14 '22 07:07 zhumingpassional

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

chennnuo avatar Jul 14 '22 08:07 chennnuo

@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?

YangletLiu avatar Jul 23 '22 02:07 YangletLiu

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

chennnuo avatar Jul 24 '22 02:07 chennnuo

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

YangletLiu avatar Jul 24 '22 03:07 YangletLiu

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

chennnuo avatar Jul 24 '22 03:07 chennnuo