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

Allow replacing a logging.StreamHandler's stream #74707

Closed
pitrou opened this issue May 31, 2017 · 6 comments
Closed

Allow replacing a logging.StreamHandler's stream #74707

pitrou opened this issue May 31, 2017 · 6 comments
Labels
3.7 type-feature

Comments

@pitrou
Copy link
Member

@pitrou pitrou commented May 31, 2017

BPO 30522
Nosy @vsajip, @pitrou, @vstinner
PRs
  • #2921
  • Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

    Show more details

    GitHub fields:

    assignee = None
    closed_at = <Date 2017-07-30.09:44:33.389>
    created_at = <Date 2017-05-31.08:09:10.627>
    labels = ['type-feature', '3.7']
    title = "Allow replacing a logging.StreamHandler's stream"
    updated_at = <Date 2017-07-30.09:44:33.388>
    user = 'https://github.com/pitrou'

    bugs.python.org fields:

    activity = <Date 2017-07-30.09:44:33.388>
    actor = 'vinay.sajip'
    assignee = 'none'
    closed = True
    closed_date = <Date 2017-07-30.09:44:33.389>
    closer = 'vinay.sajip'
    components = []
    creation = <Date 2017-05-31.08:09:10.627>
    creator = 'pitrou'
    dependencies = []
    files = []
    hgrepos = []
    issue_num = 30522
    keywords = []
    message_count = 6.0
    messages = ['294820', '294821', '294822', '297957', '297958', '299495']
    nosy_count = 3.0
    nosy_names = ['vinay.sajip', 'pitrou', 'vstinner']
    pr_nums = ['2921']
    priority = 'normal'
    resolution = 'fixed'
    stage = 'resolved'
    status = 'closed'
    superseder = None
    type = 'enhancement'
    url = 'https://bugs.python.org/issue30522'
    versions = ['Python 3.7']

    @pitrou
    Copy link
    Member Author

    @pitrou pitrou commented May 31, 2017

    Right now it is probably possible using something like:

        handler.acquire()
        try:
            handler.flush()
            handler.stream = new_stream
        finally:
            handler.release()

    but it would be nice to have an officially-supported method to do that.

    Context: if I reconfigure sys.stderr, I'd like to update all handlers that have a reference to the old sys.stderr.

    @pitrou pitrou added 3.7 type-feature labels May 31, 2017
    @vstinner
    Copy link
    Member

    @vstinner vstinner commented May 31, 2017

    Which StreamHandler class? Is this issue related to logging? If yes, please mention it in the title ;-)

    @pitrou
    Copy link
    Member Author

    @pitrou pitrou commented May 31, 2017

    Oh, yes, sorry. This is about logging.

    @pitrou pitrou changed the title Allow replacing a StreamHandler's stream Allow replacing a logging.StreamHandler's stream May 31, 2017
    @vsajip
    Copy link
    Member

    @vsajip vsajip commented Jul 8, 2017

    How about this as an API?

        def setStream(self, stream):
            """
            Sets the StreamHandler's stream to the specified value,
            if it is different.
        Returns the old stream, if the stream was changed, or None
        if it wasn't.
        """
    

    @pitrou
    Copy link
    Member Author

    @pitrou pitrou commented Jul 8, 2017

    Vinay, yes, that sounds fine to me.

    @vsajip
    Copy link
    Member

    @vsajip vsajip commented Jul 30, 2017

    New changeset 2543f50 by Vinay Sajip in branch 'master':
    bpo-30522: Implemented a method to allow setting a logging.StreamHander's stream. (GH-2921)
    2543f50

    @vsajip vsajip closed this as completed Jul 30, 2017
    @ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
    Labels
    3.7 type-feature
    Projects
    None yet
    Development

    No branches or pull requests

    3 participants