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

implement python logger wrapper #7713

Merged
merged 9 commits into from
May 20, 2021

Conversation

lbenc135
Copy link
Contributor

Fixes #4234

Motivation

Logging in the python client is not configurable, so the stdout was spammed. This PR revives the #6113 but tries to resolve the bugs that resulted the last time.

Modifications

Implemented a python logger wrapper. You can pass a python logger as an argument to the client.

Verifying this change

  • Make sure that the change passes the CI checks.

Not sure how to unit-test this. I tested it manually by building the client and trying it out with python scripts. It works as expected both with the logger forwarded and without. Also, configuring the logger also configures the log level so this fixes the problem.

Does this pull request potentially affect one of the following parts:

If yes was chosen, please highlight the changes

  • Dependencies (does it add or upgrade a dependency): no
  • The public API: yes (?)
  • The schema: no
  • The default values of configurations: no
  • The wire protocol: no
  • The rest endpoints: no
  • The admin cli options: no
  • Anything that affects deployment: no

Documentation

  • Does this pull request introduce a new feature? yes
  • If yes, how is the feature documented? inline function docs

@lbenc135 lbenc135 mentioned this pull request Jul 31, 2020
1 task
Copy link

@pinkavaj pinkavaj left a comment

Choose a reason for hiding this comment

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

Looks good. Mey be add at least some simple test, if it is managable?

pulsar-client-cpp/python/src/config.cc Outdated Show resolved Hide resolved
@lbenc135
Copy link
Contributor Author

@pinkavaj could you take another look please?

return _getLogLevelValue(level) >= _currentPythonLogLevel;
}

void log(Level level, int line, const std::string& message) {

Choose a reason for hiding this comment

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

The file and line information is not logged, but I'm not familiar with the code enought to decide what is more appropriate. From the point of developer I would preffer the file and line information in the log message.

Probably someone more familiar with this code should speek his opinion.

Otherwise looks good.

Choose a reason for hiding this comment

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

Feel free to show example and you incentive to help with decission.

Copy link
Contributor

Choose a reason for hiding this comment

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

Not having this info only truly matters if the Python Logger is connected ultimately to one or more Formatters that has tokens like filename, pathname or lineno in its format string.

It should be possible to create a LogRecord object (https://docs.python.org/3/library/logging.html#logrecord-objects) and pass it to Logger.handle method instead of using the simpler info, warning etc methods. I for one think it is not worth the trouble and the implementation is fine as-is.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thank you @Bklyn, please consider approving the PR

Copy link
Contributor

@Bklyn Bklyn left a comment

Choose a reason for hiding this comment

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

Looks good to be with the small exception of not initializing the _logger string member in the copy-ctor and assignment operator, but is this member even used for anything? I might suggest dropping it entirely.

Copy link
Contributor

@Bklyn Bklyn left a comment

Choose a reason for hiding this comment

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

Looks good to me!

@aahmed-se
Copy link
Contributor

rebase this on master.

@tuteng
Copy link
Member

tuteng commented Mar 25, 2021

/pulsarbot run-failure-checks

@tuteng tuteng added component/c++ type/enhancement The enhancements for the existing features or docs. e.g. reduce memory usage of the delayed messages labels Mar 25, 2021
@tuteng tuteng added this to the 2.8.0 milestone Mar 25, 2021
@tuteng
Copy link
Member

tuteng commented Mar 27, 2021

/pulsarbot run-failure-checks

@mianos
Copy link

mianos commented Apr 22, 2021

Does anyone know the why the unit test run was cancelled?
This PR would be great to get into our unloved python client.

@codelipenghui codelipenghui merged commit b6247fd into apache:master May 20, 2021
@Giaco9
Copy link

Giaco9 commented May 20, 2021

Hi everyone, thank you for the effort put in this pull request! Would be possible to release a version compatible with python2.7 that includes these changes?

Thank you!

@lbenc135 lbenc135 deleted the feature/python_logger branch May 20, 2021 09:12
yangl pushed a commit to yangl/pulsar that referenced this pull request Jun 23, 2021
Fixes apache#4234

### Motivation

Logging in the python client is not configurable, so the stdout was spammed. This PR revives the apache#6113 but tries to resolve the bugs that resulted the last time.

### Modifications

Implemented a python logger wrapper. You can pass a python logger as an argument to the client.

### Verifying this change

- [ ] Make sure that the change passes the CI checks.

Not sure how to unit-test this. I tested it manually by building the client and trying it out with python scripts. It works as expected both with the logger forwarded and without. Also, configuring the logger also configures the log level so this fixes the problem.
@mianos
Copy link

mianos commented Jun 30, 2021

Now this is merged I can't seem to get it working. I suspect it is because this logger is not loaded in the C++.
I would expect the massive number of INFO messages would be suppressed by doing the following:

    plogger = logging.getLogger("pulsar")
    print(f"current level {plogger.getEffectiveLevel()}")
    plogger.info("Hello info")
    plogger.setLevel(logging.ERROR)
    print(f"post setting current level {plogger.getEffectiveLevel()}")
    plogger.info("post unset info Hello info")
    client = pulsar.Client(pulsar_config.uri, logger=plogger)

I see the normal python logger suppresses the info messages but the prefect-client 2.8 still prints all
the INFO messages.
Maybe the unit test should set a logger handler and check it's not full of INFO messages?

bharanic-dev pushed a commit to bharanic-dev/pulsar that referenced this pull request Mar 18, 2022
Fixes apache#4234

### Motivation

Logging in the python client is not configurable, so the stdout was spammed. This PR revives the apache#6113 but tries to resolve the bugs that resulted the last time.

### Modifications

Implemented a python logger wrapper. You can pass a python logger as an argument to the client.

### Verifying this change

- [ ] Make sure that the change passes the CI checks.

Not sure how to unit-test this. I tested it manually by building the client and trying it out with python scripts. It works as expected both with the logger forwarded and without. Also, configuring the logger also configures the log level so this fixes the problem.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/client type/enhancement The enhancements for the existing features or docs. e.g. reduce memory usage of the delayed messages
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Make client logging configurable
9 participants