Skip to content

Commit

Permalink
[FIX] hw_drivers: Redirect exceptions to log file
Browse files Browse the repository at this point in the history
Exceptions were logged to stderr so we couldn't see them when Odoo was
running as a service on the IoT Box. We now redirect stderr to the logger
to see track errors in the log file too.

closes odoo#41011

Taskid: 2146835
Signed-off-by: Quentin Lejeune (qle) <[email protected]>
  • Loading branch information
aprieels committed Nov 28, 2019
1 parent 0ef0f33 commit 54a1919
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions addons/hw_drivers/controllers/driver.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import urllib3
import os
import socket
import sys
from importlib import util
import v4l2
from fcntl import ioctl
Expand Down Expand Up @@ -97,6 +98,27 @@ def connect_box(self, token):
with open(image, 'rb') as f:
return f.read()

#----------------------------------------------------------
# Log Exceptions
#----------------------------------------------------------

class ExceptionLogger:
"""
Redirect Exceptions to the logger to keep track of them in the log file.
"""

def __init__(self):
self.logger = logging.getLogger()

def write(self, message):
if message != '\n':
self.logger.err(message)

def flush(self):
pass

sys.stderr = ExceptionLogger()

#----------------------------------------------------------
# Drivers
#----------------------------------------------------------
Expand Down

0 comments on commit 54a1919

Please sign in to comment.