MCPcopy Index your code
hub / github.com/python/cpython / __init__

Method __init__

Lib/logging/handlers.py:223–288  ·  view source on GitHub ↗
(self, filename, when='h', interval=1, backupCount=0,
                 encoding=None, delay=False, utc=False, atTime=None,
                 errors=None)

Source from the content-addressed store, hash-verified

221 files are kept - the oldest ones are deleted.
222 """
223 def __init__(self, filename, when='h', interval=1, backupCount=0,
224 encoding=None, delay=False, utc=False, atTime=None,
225 errors=None):
226 encoding = io.text_encoding(encoding)
227 BaseRotatingHandler.__init__(self, filename, 'a', encoding=encoding,
228 delay=delay, errors=errors)
229 self.when = when.upper()
230 self.backupCount = backupCount
231 self.utc = utc
232 self.atTime = atTime
233 # Calculate the real rollover interval, which is just the number of
234 # seconds between rollovers. Also set the filename suffix used when
235 # a rollover occurs. Current 'when' events supported:
236 # S - Seconds
237 # M - Minutes
238 # H - Hours
239 # D - Days
240 # midnight - roll over at midnight
241 # W{0-6} - roll over on a certain day; 0 - Monday
242 #
243 # Case of the 'when' specifier is not important; lower or upper case
244 # will work.
245 if self.when == 'S':
246 self.interval = 1 # one second
247 self.suffix = "%Y-%m-%d_%H-%M-%S"
248 extMatch = r"(?<!\d)\d{4}-\d{2}-\d{2}_\d{2}-\d{2}-\d{2}(?!\d)"
249 elif self.when == 'M':
250 self.interval = 60 # one minute
251 self.suffix = "%Y-%m-%d_%H-%M"
252 extMatch = r"(?<!\d)\d{4}-\d{2}-\d{2}_\d{2}-\d{2}(?!\d)"
253 elif self.when == 'H':
254 self.interval = 60 * 60 # one hour
255 self.suffix = "%Y-%m-%d_%H"
256 extMatch = r"(?<!\d)\d{4}-\d{2}-\d{2}_\d{2}(?!\d)"
257 elif self.when == 'D' or self.when == 'MIDNIGHT':
258 self.interval = 60 * 60 * 24 # one day
259 self.suffix = "%Y-%m-%d"
260 extMatch = r"(?<!\d)\d{4}-\d{2}-\d{2}(?!\d)"
261 elif self.when.startswith('W'):
262 self.interval = 60 * 60 * 24 * 7 # one week
263 if len(self.when) != 2:
264 raise ValueError("You must specify a day for weekly rollover from 0 to 6 (0 is Monday): %s" % self.when)
265 if self.when[1] < '0' or self.when[1] > '6':
266 raise ValueError("Invalid day specified for weekly rollover: %s" % self.when)
267 self.dayOfWeek = int(self.when[1])
268 self.suffix = "%Y-%m-%d"
269 extMatch = r"(?<!\d)\d{4}-\d{2}-\d{2}(?!\d)"
270 else:
271 raise ValueError("Invalid rollover interval specified: %s" % self.when)
272
273 # extMatch is a pattern for matching a datetime suffix in a file name.
274 # After custom naming, it is no longer guaranteed to be separated by
275 # periods from other parts of the filename. The lookup statements
276 # (?<!\d) and (?!\d) ensure that the datetime suffix (which itself
277 # starts and ends with digits) is not preceded or followed by digits.
278 # This reduces the number of false matches and improves performance.
279 self.extMatch = re.compile(extMatch, re.ASCII)
280 self.interval = self.interval * interval # multiply by units requested

Callers

nothing calls this directly

Calls 8

computeRolloverMethod · 0.95
__init__Method · 0.45
upperMethod · 0.45
startswithMethod · 0.45
compileMethod · 0.45
existsMethod · 0.45
statMethod · 0.45
timeMethod · 0.45

Tested by

no test coverage detected