diff options
Diffstat (limited to 'src/logging.py')
-rw-r--r-- | src/logging.py | 24 |
1 files changed, 16 insertions, 8 deletions
diff --git a/src/logging.py b/src/logging.py index 4bbedb9d..bb22e5c9 100644 --- a/src/logging.py +++ b/src/logging.py @@ -17,28 +17,36 @@ # You should have received a copy of the GNU General Public License # along with Poezio. If not, see <http://www.gnu.org/licenses/>. -from config import config import sys from datetime import datetime - +from config import config class Logger(object): """ Appends things to files. Error/information/warning logs and also log the conversations to logfiles """ - def __init__(self): - self.logfile = config.get('logfile') + def __init__(self):# , logfile, loglevel): + self.logfile = config.get('logfile', 'logs') + self.loglevel = config.get('loglevel', 3) + # self.logfile = logfile + # self.loglevel = loglevel + + def info(self, msg): + if self.logfile and self.loglevel >= 3: + fd = open(self.logfile, 'a') + fd.write(datetime.now().strftime("%H:%M:%S") + ' Info [' + msg + ']\n') + fd.close() def warning(self, msg): - if self.logfile: + if self.logfile and self.loglevel >= 2: fd = open(self.logfile, 'a') - fd.write(datetime.now().strftime("%H:%M:%S") + ' Warning [' + msg + ']') + fd.write(datetime.now().strftime("%H:%M:%S") + ' Warning [' + msg + ']\n') fd.close() def error(self, msg): - if self.logfile: + if self.logfile and self.loglevel >= 1: fd = open(self.logfile, 'a') - fd.write(datetime.now().strftime("%H:%M:%S") + ' Error [' + msg + ']') + fd.write(datetime.now().strftime("%H:%M:%S") + ' Error [' + msg + ']\n') fd.close() sys.exit(-1) |