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

Improve how we do logging #1325

Merged
merged 1 commit into from
Apr 14, 2020
Merged

Improve how we do logging #1325

merged 1 commit into from
Apr 14, 2020

Conversation

heyman
Copy link
Member

@heyman heyman commented Apr 13, 2020

PR for #1285. Does the following:

  • We no longer wrap sys.stdout and sys.stderr (yay!). print() statements in locust scripts will no longer automatically go into the log. If someone wants to add entries to the log they can use the root logger instead (logging.info(…)), or any custom logger named "locust.*".
  • The "console_logger" logger has been removed. For printing stats to the console we now use a logger called "locust.stats_logger". For printing output when using flags such as --show-task-ratio or -l we now use print() statements instead.
  • We now set up an exception handler that logs any unhandled exception, for every greenlet we spawn (using Greenlet.link_exception) unless they already have their own exception handler (e.g. Locust User greenlets).
  • Only allow valid --loglevel values.
  • Better tests.

We no longer wrap stdout and stderr (yay!). print() statements in locust scripts will no longer automatically go into the log. If someone wants to add entries to the log they can use the root logger instead (logging.info(…)), or any custom logger named "locust.*".

The "console_logger" logger has been removed. For printing stats to the console we now use a logger called "locust.stats_logger". For printing output when using flags such as --show-task-ratio or -l we now use print() statements instead.

We now set up an exception handler that logs any unhandled exception, for every greenlet we spawn (using Greenlet.link_exception) unless they already have their own exception handler (e.g. Locust User greenlets).

Only allow valid --loglevel arguments.
@heyman heyman linked an issue Apr 13, 2020 that may be closed by this pull request
@codecov
Copy link

codecov bot commented Apr 13, 2020

Codecov Report

Merging #1325 into master will decrease coverage by 0.21%.
The diff coverage is 46.66%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #1325      +/-   ##
==========================================
- Coverage   80.99%   80.77%   -0.22%     
==========================================
  Files          24       24              
  Lines        2199     2190       -9     
  Branches      333      334       +1     
==========================================
- Hits         1781     1769      -12     
- Misses        331      334       +3     
  Partials       87       87              
Impacted Files Coverage Δ
locust/inspectlocust.py 71.87% <0.00%> (-0.86%) ⬇️
locust/main.py 21.57% <5.88%> (-0.71%) ⬇️
locust/log.py 56.25% <50.00%> (-7.64%) ⬇️
locust/runners.py 78.78% <100.00%> (-0.21%) ⬇️
locust/stats.py 88.73% <100.00%> (+0.02%) ⬆️
locust/web.py 89.65% <0.00%> (-1.15%) ⬇️
locust/core.py 98.17% <0.00%> (+0.45%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update ada1ffa...fba7aff. Read the comment docs.

@cyberw
Copy link
Collaborator

cyberw commented Apr 13, 2020

Looks good! But is there some reason plain print() statements cant also work?

@heyman
Copy link
Member Author

heyman commented Apr 13, 2020

But is there some reason plain print() statements cant also work?

Do you mean why print() statements won't automatically go into the log file? That was an effect of us wrapping sys.stdout which seems like a strange and invasive behaviour. Print statements still work, it's just that they now does what one would expect them to do in python (just print to the console).

@cyberw
Copy link
Collaborator

cyberw commented Apr 13, 2020

But is there some reason plain print() statements cant also work?

Do you mean why print() statements won't automatically go into the log file? That was an effect of us wrapping sys.stdout which seems like a strange and invasive behaviour. Print statements still work, it's just that they now does what one would expect them to do in python (just print to the console).

Ah, I misunderstood you and thought you meant that print statements no longer work for printing to stdout :)

+1

@heyman heyman marked this pull request as ready for review April 13, 2020 22:23
@heyman heyman merged commit 5844fd5 into master Apr 14, 2020
@cyberw cyberw deleted the logging-refactor branch August 19, 2020 08:08
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.

Change how logging is handled
2 participants