This method iterates through all of the providers handlers looking for the FileHandler types. A lock is acquired, the underlying stream closed, reopened, then the lock is released. This method should be called when logs are to be rotated by an external process. The simplest way t
(handlers)
| 46 | |
| 47 | |
| 48 | def reopen_log_files(handlers): |
| 49 | """ |
| 50 | This method iterates through all of the providers handlers looking for the FileHandler types. |
| 51 | |
| 52 | A lock is acquired, the underlying stream closed, reopened, then the lock is released. |
| 53 | |
| 54 | |
| 55 | This method should be called when logs are to be rotated by an external process. The simplest |
| 56 | way to do this is via a signal handler. |
| 57 | """ |
| 58 | for handler in handlers: |
| 59 | if not isinstance(handler, logging.FileHandler): |
| 60 | continue |
| 61 | |
| 62 | LOG.info( |
| 63 | 'Re-opening log file "%s" with mode "%s"\n' |
| 64 | % (handler.baseFilename, handler.mode) |
| 65 | ) |
| 66 | |
| 67 | try: |
| 68 | handler.acquire() |
| 69 | handler.stream.close() |
| 70 | handler.stream = open(handler.baseFilename, handler.mode) |
| 71 | finally: |
| 72 | try: |
| 73 | handler.release() |
| 74 | except RuntimeError as e: |
| 75 | if "cannot release" in six.text_type(e): |
| 76 | # Release failed which most likely indicates that acquire failed |
| 77 | # and lock was never acquired |
| 78 | LOG.warning("Failed to release lock", exc_info=True) |
| 79 | else: |
| 80 | raise e |
| 81 | |
| 82 | |
| 83 | def set_log_level_for_all_handlers(logger, level=logging.DEBUG): |
no test coverage detected