This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author andriusl
Recipients andriusl, peter.otten, vinay.sajip, xtreak
Date 2019-03-07.08:04:56
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <CAFChh+aYEwvX5x28xU=ftTkQpoBF7co=8LZsaqXbP25hLoH3EA@mail.gmail.com>
In-reply-to <1551939182.06.0.434904530366.issue36193@roundup.psfhosted.org>
Content
Ok. Thanks for the clarification.

On Thu, Mar 7, 2019, 08:13 Vinay Sajip <report@bugs.python.org> wrote:

>
> Vinay Sajip <vinay_sajip@yahoo.co.uk> added the comment:
>
> The StreamHandler allows you to specify *exactly* which stream you want to
> use to log to; sys.stderr is provided as a convenient default argument
> because that's what a lot of people want a lot of the time.
>
> This is typically done at logging configuration time, or whenever a
> StreamHandler is created. This is done implicitly by your logging.warning()
> call (as documented, this calls logging.basicConfig(), which adds a
> StreamHandler using whatever sys.stderr is set to at the time the
> StreamHandler is instantiated). Also documented is that basicConfig() is
> only effective once (it will not do anything if a handler has already been
> added to the root logger - it is only meant to be use for simple one-off
> scripts). The documentation for basicConfig() is clear:
>
> "Does basic configuration for the logging system by creating a
> StreamHandler with a default Formatter and adding it to the root logger.
> The functions debug(), info(), warning(), error() and critical() will call
> basicConfig() automatically if no handlers are defined for the root logger.
>
> This function does nothing if the root logger already has handlers
> configured for it."
>
> If you want to use the real console streams, don't use logging.warning(),
> but instead explicitly call basicConfig() using __stderr__, as Peter says.
> Alternatively, use the approach suggested in the cookbook for
> context-sensitive logging:
>
>
> https://docs.python.org/3/howto/logging-cookbook.html#using-a-context-manager-for-selective-logging
>
> Closing, as this is not a bug in logging.
>
> ----------
> resolution:  -> not a bug
> stage:  -> resolved
> status: open -> closed
>
> _______________________________________
> Python tracker <report@bugs.python.org>
> <https://bugs.python.org/issue36193>
> _______________________________________
>
History
Date User Action Args
2019-03-07 08:04:56andriuslsetrecipients: + andriusl, vinay.sajip, peter.otten, xtreak
2019-03-07 08:04:56andriusllinkissue36193 messages
2019-03-07 08:04:56andriuslcreate