mirror of
https://github.com/bringout/oca-ocb-hw.git
synced 2026-04-20 03:02:07 +02:00
Initial commit: Hw packages
This commit is contained in:
commit
a9d00500da
161 changed files with 10506 additions and 0 deletions
|
|
@ -0,0 +1,34 @@
|
|||
|
||||
from io import StringIO
|
||||
|
||||
import logging
|
||||
import sys
|
||||
|
||||
_logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
class ExceptionLogger:
|
||||
"""
|
||||
Redirect any unhandled python exception to the logger to keep track of them in the log file.
|
||||
"""
|
||||
def __init__(self):
|
||||
self._buffer = StringIO()
|
||||
|
||||
def write(self, message):
|
||||
self._buffer.write(message)
|
||||
if message.endswith('\n'):
|
||||
self._flush_buffer()
|
||||
|
||||
def _flush_buffer(self):
|
||||
self._buffer.seek(0)
|
||||
_logger.error(self._buffer.getvalue().rstrip('\n'))
|
||||
self._buffer = StringIO() # Reset the buffer
|
||||
|
||||
def flush(self):
|
||||
if self._buffer.tell() > 0:
|
||||
self._flush_buffer()
|
||||
|
||||
def close(self):
|
||||
self.flush()
|
||||
|
||||
sys.stderr = ExceptionLogger()
|
||||
Loading…
Add table
Add a link
Reference in a new issue