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

Update qlib logger #393

Merged
merged 8 commits into from Apr 23, 2021
Merged

Update qlib logger #393

merged 8 commits into from Apr 23, 2021

Conversation

Derek-Wds
Copy link
Contributor

@Derek-Wds Derek-Wds commented Apr 16, 2021

Description

The first commit solves the problem of pickling logger object under certain python version. But, I'm still figuring out how to maintain the original docstring of the logger.

First trial: now use help function will print all the docstrings of QlibLogger, but the docstring hints won't show up while using IDEs such as VSCode.

Motivation and Context

How Has This Been Tested?

  • Pass the test by running: pytest qlib/tests/test_all_pipeline.py under upper directory of qlib.
  • If you are adding a new feature, test on your own test scripts.

Screenshots of Test Results (if appropriate):

  1. Pipeline test:
  2. Your own tests:

Types of changes

  • Fix bugs
  • Add new feature
  • Update documentation

@Derek-Wds Derek-Wds added the bug Something isn't working label Apr 16, 2021
@Derek-Wds Derek-Wds marked this pull request as draft April 16, 2021 02:06
@Derek-Wds Derek-Wds marked this pull request as ready for review April 19, 2021 03:36
@Derek-Wds Derek-Wds requested a review from you-n-g April 19, 2021 03:36
qlib/log.py Outdated Show resolved Hide resolved
qlib/log.py Outdated
super().__init__(name, bases, dic)

def __new__(cls, name, bases, dict):
wrapper_dict = type(logging.getLogger("MetaLogger")).__dict__.copy()
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not use Logger directly?

Copy link
Contributor Author

@Derek-Wds Derek-Wds Apr 22, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

type(logging.Logger) will give the result of <class 'type'>, while calling type(logger object) will give the result <class 'logging.Logger'>. The aim of wrapper dict here aimed to get the type dictionary of logger object which needs a logger instance here (since we need the information and messages in the dict for making help work).

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will it be different by replacing type(logging.getLogger("MetaLogger")) with logging.Logger?
Why should we create a Logger instance here?

qlib/log.py Outdated
def __new__(cls, name, bases, dict):
wrapper_dict = type(logging.getLogger("MetaLogger")).__dict__.copy()
wrapper_dict.update(dict)
wrapper_dict["__doc__"] = logging.getLogger("MetaLogger").__doc__
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not use logging.Logger.__doc__ ?

Copy link
Contributor Author

@Derek-Wds Derek-Wds Apr 22, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, we can use logging.Logger.__doc__ here, which will have the same results as doing so with an instance.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why should we create a Logger instance here instead of using the class?
Using the class directly takes fewer steps and the code looks simpler

qlib/log.py Outdated Show resolved Hide resolved
@you-n-g you-n-g merged commit 50be7a9 into microsoft:main Apr 23, 2021
@Derek-Wds Derek-Wds mentioned this pull request Apr 29, 2021
5 tasks
qianyun210603 pushed a commit to qianyun210603/qlib that referenced this pull request Mar 23, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants