32 lines
910 B
Python
32 lines
910 B
Python
# -*- coding: utf-8 -*-
|
|
from datetime import datetime
|
|
from TYPES import LogTypes
|
|
from DataBase import DataBase
|
|
from Config import DBPath
|
|
|
|
|
|
class Log(object):
|
|
|
|
def __init__(self, logtype: LogTypes, location: str, message: str) -> None:
|
|
self.logtype = logtype
|
|
self.location = location
|
|
self.msg = message
|
|
self.toDB()
|
|
|
|
date = datetime.now().date()
|
|
time = datetime.now().time().strftime("%H:%M:%S")
|
|
|
|
def __str__(self):
|
|
return f"[{self.date} | {self.time}] [{self.logtype.value}] [{self.location}] {self.msg}"
|
|
|
|
def toDB(self):
|
|
db = DataBase(DBPath, "logs")
|
|
db.createTable("date TEXT, time TEXT, type TEXT, location TEXT, message TEXT")
|
|
db.insert({
|
|
"date": self.date,
|
|
"time": self.time,
|
|
"type": self.logtype.value,
|
|
"location": self.location,
|
|
"message": self.msg
|
|
})
|