Determine if rollover should occur. Basically, see if the supplied record would cause the file to exceed the size limit we have.
(self, record)
| 187 | self.stream = self._open() |
| 188 | |
| 189 | def shouldRollover(self, record): |
| 190 | """ |
| 191 | Determine if rollover should occur. |
| 192 | |
| 193 | Basically, see if the supplied record would cause the file to exceed |
| 194 | the size limit we have. |
| 195 | """ |
| 196 | if self.stream is None: # delay was set... |
| 197 | self.stream = self._open() |
| 198 | if self.maxBytes > 0: # are we rolling over? |
| 199 | try: |
| 200 | pos = self.stream.tell() |
| 201 | except io.UnsupportedOperation: |
| 202 | # gh-143237: Never rollover a named pipe. |
| 203 | return False |
| 204 | if not pos: |
| 205 | # gh-116263: Never rollover an empty file |
| 206 | return False |
| 207 | msg = "%s\n" % self.format(record) |
| 208 | if pos + len(msg) >= self.maxBytes: |
| 209 | # See bpo-45401: Never rollover anything other than regular files |
| 210 | if os.path.exists(self.baseFilename) and not os.path.isfile(self.baseFilename): |
| 211 | return False |
| 212 | return True |
| 213 | return False |
| 214 | |
| 215 | class TimedRotatingFileHandler(BaseRotatingHandler): |
| 216 | """ |