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

Logging failes for rotating file log (during rollOver) #40174

Closed
smeyers2002 mannequin opened this issue Apr 22, 2004 · 3 comments
Closed

Logging failes for rotating file log (during rollOver) #40174

smeyers2002 mannequin opened this issue Apr 22, 2004 · 3 comments
Assignees
Labels
stdlib Python modules in the Lib dir

Comments

@smeyers2002
Copy link
Mannequin

smeyers2002 mannequin commented Apr 22, 2004

BPO 939836
Nosy @tim-one, @vsajip
Files
  • log.py: Python script that generates the descibed error
  • 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 = 'https://github.com/vsajip'
    closed_at = <Date 2004-04-29.08:55:28.000>
    created_at = <Date 2004-04-22.07:25:10.000>
    labels = ['library']
    title = 'Logging failes for rotating file log (during rollOver)'
    updated_at = <Date 2004-04-29.08:55:28.000>
    user = 'https://bugs.python.org/smeyers2002'

    bugs.python.org fields:

    activity = <Date 2004-04-29.08:55:28.000>
    actor = 'smeyers2002'
    assignee = 'vinay.sajip'
    closed = True
    closed_date = None
    closer = None
    components = ['Library (Lib)']
    creation = <Date 2004-04-22.07:25:10.000>
    creator = 'smeyers2002'
    dependencies = []
    files = ['1253']
    hgrepos = []
    issue_num = 939836
    keywords = []
    message_count = 3.0
    messages = ['20557', '20558', '20559']
    nosy_count = 3.0
    nosy_names = ['tim.peters', 'vinay.sajip', 'smeyers2002']
    pr_nums = []
    priority = 'normal'
    resolution = None
    stage = None
    status = 'closed'
    superseder = None
    type = None
    url = 'https://bugs.python.org/issue939836'
    versions = ['Python 2.3']

    @smeyers2002
    Copy link
    Mannequin Author

    smeyers2002 mannequin commented Apr 22, 2004

    I have a problem with the python logging. The attached
    python file 'log.py' initializes the python logging (rotating
    log file) and starts writing lines in a log file.

    Everything works, if the line 'log.refresh' is commented
    out. If the line is not commented out, I always get an
    error by the first rollOver. So each time when I re-
    initialize the logging (=method refresh in my code) I get
    this error (see below). What can be the problem?
    OS information: Windows XP Professional, version
    5.1.2600 Service Pack 1

    Traceback (most recent call last):
      File "log.py", line 21, in ?
        log.logger.info(" I am line "+str(i))
      File "C:\Python23\lib\logging\__init__.py", line 893, in 
    info
        apply(self._log, (INFO, msg, args), kwargs)
      File "C:\Python23\lib\logging\__init__.py", line 994, in 
    _log
        self.handle(record)
      File "C:\Python23\lib\logging\__init__.py", line 1004, in 
    handle
        self.callHandlers(record)
      File "C:\Python23\lib\logging\__init__.py", line 1037, in 
    callHandlers
        hdlr.handle(record)
      File "C:\Python23\lib\logging\__init__.py", line 592, in 
    handle
        self.emit(record)
      File "C:\Python23\lib\logging\handlers.py", line 105, in 
    emit
        self.doRollover()
      File "C:\Python23\lib\logging\handlers.py", line 90, in 
    doRollover
        os.rename(self.baseFilename, dfn)
    OSError: [Errno 13] Permission denied

    PS: Sometimes I also get the error 'ValueError: I/O
    operation on closed file'

    @smeyers2002 smeyers2002 mannequin closed this as completed Apr 22, 2004
    @smeyers2002 smeyers2002 mannequin assigned vsajip Apr 22, 2004
    @smeyers2002 smeyers2002 mannequin added the stdlib Python modules in the Lib dir label Apr 22, 2004
    @smeyers2002 smeyers2002 mannequin closed this as completed Apr 22, 2004
    @smeyers2002 smeyers2002 mannequin assigned vsajip Apr 22, 2004
    @smeyers2002 smeyers2002 mannequin added the stdlib Python modules in the Lib dir label Apr 22, 2004
    @tim-one
    Copy link
    Member

    tim-one commented Apr 22, 2004

    Logged In: YES
    user_id=31435

    Windows is unique in that it will not allow renaming (or
    deleting) a file that's open. I expect that by calling refresh()
    all the time, you're creating additional new objects that have
    C:\log.txt open, so that it's impossible for rollover to rename
    C:\log.txt on Windows. There's nothing the logging package
    can do about that.

    You're also adding an endless number of redundant handlers
    to the same logger. Try this:

    1. In your __init__ method, set
         self.logger = None
    1. Start your refresh() method with
            if self.logger is not None:
                self.rotatingFileLogHandler.close()
                self.logger.removeHandler(self.rotatingFileLogHandler)

    Closing the old handler arranges to close the C:\log.txt file, so
    that it's *possible* to rename it on Windows. Removing the
    old handler from the logger should prevent seeing an
    unpredictable number of copies of individual log msgs, and
    probably prevent some "I/O operation on closed file" screwups
    too.

    @smeyers2002
    Copy link
    Mannequin Author

    smeyers2002 mannequin commented Apr 29, 2004

    Logged In: YES
    user_id=1026630

    Thanks Tim, this solved the problem.

    @ezio-melotti ezio-melotti transferred this issue from another repository Apr 9, 2022
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
    Labels
    stdlib Python modules in the Lib dir
    Projects
    None yet
    Development

    No branches or pull requests

    2 participants