From ff72fbd1d73068817e09b5fd11b620ac463e06c3 Mon Sep 17 00:00:00 2001 From: chrys87 Date: Fri, 8 Jul 2016 11:56:42 +0200 Subject: [PATCH] update debug --- src/fenrir-package/utils/debug.py | 33 ++++++++++++++++++++++--------- 1 file changed, 24 insertions(+), 9 deletions(-) diff --git a/src/fenrir-package/utils/debug.py b/src/fenrir-package/utils/debug.py index 31affea1..971e22db 100644 --- a/src/fenrir-package/utils/debug.py +++ b/src/fenrir-package/utils/debug.py @@ -2,28 +2,40 @@ # Debugger module for the Fenrir screen reader. -ERROR = 0 -WARNING = 1 -INFO = 2 +DEACTIVE = 0 +ERROR = 1 +WARNING = 2 +INFO = 3 class debug(): def __init__(self, fileName='/var/log/fenrir.log', level = ERROR): self._level = level - self._fileName= fileName - self._file = open(self._fileName,'w') - self._fileOpened = True + self._fileName = fileName + self._file = '' + self._fileOpened = False def openDebugFile(self, fileName = ''): + self._fileOpened = False if fileName != '': self._fileName = fileName if self._fileName != '': self.file = open(self._fileName,'w') self._fileOpened = True - def writeLog(self, text, level = ERROR): + def writeDebugOut(self, envirionment, text): + if not envirionment['generalInformation']['debugEnabled']: + if self._fileOpened: + self.closeDebugFile() + return + else: + if not self._fileOpened: + self.openDebugFile() + self.writeLog(environment, text): + + def writeLog(self, environment, text): if not self._fileOpened: return False - if self._level < level: + if self._level < envirionment['generalInformation']['debugLevel']: return False self._file.write(text + '\n') return True @@ -45,6 +57,9 @@ class debug(): return self._fileName def setDebugFile(self, fileName): - self._fileName = fileName + self.closeDebugFile() + if self._fileOpened: + self.openDebugFile(self, fileName): +