mirror of
https://github.com/python/cpython.git
synced 2025-10-28 01:00:34 +00:00
Closes #27493: accepted Path objects in file handlers for logging.
This commit is contained in:
parent
d3afb62b8f
commit
638e622055
4 changed files with 44 additions and 2 deletions
|
|
@ -1,4 +1,4 @@
|
|||
# Copyright 2001-2015 by Vinay Sajip. All Rights Reserved.
|
||||
# Copyright 2001-2016 by Vinay Sajip. All Rights Reserved.
|
||||
#
|
||||
# Permission to use, copy, modify, and distribute this software and its
|
||||
# documentation for any purpose and without fee is hereby granted,
|
||||
|
|
@ -18,7 +18,7 @@
|
|||
Logging package for Python. Based on PEP 282 and comments thereto in
|
||||
comp.lang.python.
|
||||
|
||||
Copyright (C) 2001-2015 Vinay Sajip. All Rights Reserved.
|
||||
Copyright (C) 2001-2016 Vinay Sajip. All Rights Reserved.
|
||||
|
||||
To use, simply 'import logging' and log away!
|
||||
"""
|
||||
|
|
@ -994,6 +994,8 @@ class FileHandler(StreamHandler):
|
|||
"""
|
||||
Open the specified file and use it as the stream for logging.
|
||||
"""
|
||||
# Issue #27493: add support for Path objects to be passed in
|
||||
filename = os.fspath(filename)
|
||||
#keep the absolute path, otherwise derived classes which use this
|
||||
#may come a cropper when the current directory changes
|
||||
self.baseFilename = os.path.abspath(filename)
|
||||
|
|
|
|||
|
|
@ -246,6 +246,9 @@ class TimedRotatingFileHandler(BaseRotatingHandler):
|
|||
|
||||
self.extMatch = re.compile(self.extMatch, re.ASCII)
|
||||
self.interval = self.interval * interval # multiply by units requested
|
||||
# The following line added because the filename passed in could be a
|
||||
# path object (see Issue #27493), but self.baseFilename will be a string
|
||||
filename = self.baseFilename
|
||||
if os.path.exists(filename):
|
||||
t = os.stat(filename)[ST_MTIME]
|
||||
else:
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue