MCPcopy Index your code
hub / github.com/RustPython/RustPython / __init__

Method __init__

Lib/logging/handlers.py:219–284  ·  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

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

Callers

nothing calls this directly

Calls 9

computeRolloverMethod · 0.95
lenFunction · 0.85
__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