Open the specified file and use it as the stream for logging. By default, the file grows indefinitely. You can specify particular values of maxBytes and backupCount to allow the file to rollover at a predetermined size. Rollover occurs whenever the current
(self, filename, mode='a', maxBytes=0, backupCount=0,
encoding=None, delay=False, errors=None)
| 128 | to the next when the current file reaches a certain size. |
| 129 | """ |
| 130 | def __init__(self, filename, mode='a', maxBytes=0, backupCount=0, |
| 131 | encoding=None, delay=False, errors=None): |
| 132 | """ |
| 133 | Open the specified file and use it as the stream for logging. |
| 134 | |
| 135 | By default, the file grows indefinitely. You can specify particular |
| 136 | values of maxBytes and backupCount to allow the file to rollover at |
| 137 | a predetermined size. |
| 138 | |
| 139 | Rollover occurs whenever the current log file is nearly maxBytes in |
| 140 | length. If backupCount is >= 1, the system will successively create |
| 141 | new files with the same pathname as the base file, but with extensions |
| 142 | ".1", ".2" etc. appended to it. For example, with a backupCount of 5 |
| 143 | and a base file name of "app.log", you would get "app.log", |
| 144 | "app.log.1", "app.log.2", ... through to "app.log.5". The file being |
| 145 | written to is always "app.log" - when it gets filled up, it is closed |
| 146 | and renamed to "app.log.1", and if files "app.log.1", "app.log.2" etc. |
| 147 | exist, then they are renamed to "app.log.2", "app.log.3" etc. |
| 148 | respectively. |
| 149 | |
| 150 | If maxBytes is zero, rollover never occurs. |
| 151 | """ |
| 152 | # If rotation/rollover is wanted, it doesn't make sense to use another |
| 153 | # mode. If for example 'w' were specified, then if there were multiple |
| 154 | # runs of the calling application, the logs from previous runs would be |
| 155 | # lost if the 'w' is respected, because the log file would be truncated |
| 156 | # on each run. |
| 157 | if maxBytes > 0: |
| 158 | mode = 'a' |
| 159 | if "b" not in mode: |
| 160 | encoding = io.text_encoding(encoding) |
| 161 | BaseRotatingHandler.__init__(self, filename, mode, encoding=encoding, |
| 162 | delay=delay, errors=errors) |
| 163 | self.maxBytes = maxBytes |
| 164 | self.backupCount = backupCount |
| 165 | |
| 166 | def doRollover(self): |
| 167 | """ |