Skip to content

Allow replacing a logging.StreamHandler's stream #74707

Description

@pitrou
BPO 30522
Nosy @vsajip, @pitrou, @vstinner
PRs
  • bpo-30522: Implemented a method to allow setting a logging.StreamHand… #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']

    Activity

    1. pitrou commented on May 31, 2017

      @pitrou
      MemberAuthor

      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.

    2. vstinner commented on May 31, 2017

      @vstinner
      Member

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

    3. pitrou commented on May 31, 2017

      @pitrou
      MemberAuthor

      Oh, yes, sorry. This is about logging.

    4. changed the title [-]Allow replacing a StreamHandler's stream[/-] [+]Allow replacing a logging.StreamHandler's stream[/+] on May 31, 2017
    5. vsajip commented on Jul 8, 2017

      @vsajip
      Member

      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.
          """
      
    6. pitrou commented on Jul 8, 2017

      @pitrou
      MemberAuthor

      Vinay, yes, that sounds fine to me.

    7. vsajip commented on Jul 30, 2017

      @vsajip
      Member

      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

    8. transferred this issue fromon Apr 10, 2022
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

    Metadata

    Metadata

    Assignees

    No one assigned

      Labels

      3.7 (EOL)end of lifetype-featureA feature request or enhancement

      Projects

      No projects

        Milestone

        No milestone

        Relationships

        None yet

        Development

        No branches or pull requests

        Issue actions