Skip to content

Commit

Permalink
update logger to hight warning and error (#36)
Browse files Browse the repository at this point in the history
  • Loading branch information
Juice-XIJ authored Apr 26, 2022
1 parent 389f2aa commit 18943ae
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 5 deletions.
4 changes: 2 additions & 2 deletions forza.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,9 +138,9 @@ def analyze(self, performance_profile: bool = True, is_gui: bool = False):
# rpm vs speed at 1, 1
helper.plot_rpm_speed(self, ax, 1, 1)
plt.show()
except BaseException as e:
except Exception as e:
self.logger.exception(e)
self.logger.info("something went wrong. please re-test the car")
self.logger.error("something went wrong. please re-test the car")
finally:
self.logger.debug(f'{self.analyze.__name__} ended')

Expand Down
12 changes: 9 additions & 3 deletions logger.py
Original file line number Diff line number Diff line change
@@ -1,25 +1,31 @@
import logging
import os
import sys
from tkinter.scrolledtext import ScrolledText

import constants


class TextHandler(logging.Handler):

def __init__(self, text):
def __init__(self, text: ScrolledText):
# run the regular Handler __init__
logging.Handler.__init__(self)
self.text = text
self.text.tag_config(logging.getLevelName(logging.DEBUG))
self.text.tag_config(logging.getLevelName(logging.INFO))
self.text.tag_config(logging.getLevelName(logging.WARNING), foreground='#fca862')
self.text.tag_config(logging.getLevelName(logging.ERROR), foreground='#ff3333')
self.text.tag_config(logging.getLevelName(logging.CRITICAL), foreground='#b30000')
self.line_limitation = 6000.0
self.line_check = 6500.0

def num_lines(self):
return int(self.text.index('end').split('.')[0]) - 1

def emit(self, record):
def emit(self, record: logging.LogRecord):
msg = self.format(record)
self.text.insert('end', msg + '\n')
self.text.insert('end', msg + '\n', record.levelname)
self.text.see('end')
if self.num_lines() > self.line_check:
self.text.delete(1.0, self.line_check - self.line_limitation)
Expand Down

0 comments on commit 18943ae

Please sign in to comment.