add logger
This commit is contained in:
@@ -5,7 +5,7 @@ from pathlib import Path
|
|||||||
from src import settings
|
from src import settings
|
||||||
from typing import Any, List, Optional, Tuple, Union
|
from typing import Any, List, Optional, Tuple, Union
|
||||||
import datetime
|
import datetime
|
||||||
from src import logger
|
|
||||||
from src.backend.db import (
|
from src.backend.db import (
|
||||||
CREATE_ELSA_FILES_TABLE,
|
CREATE_ELSA_FILES_TABLE,
|
||||||
CREATE_ELSA_MEDIA_TABLE,
|
CREATE_ELSA_MEDIA_TABLE,
|
||||||
@@ -25,6 +25,20 @@ from src.logic.constants import SEMAP_MEDIA_ACCOUNTS
|
|||||||
from src.utils import create_blob, dump_pickle, load_pickle
|
from src.utils import create_blob, dump_pickle, load_pickle
|
||||||
from .semester import Semester
|
from .semester import Semester
|
||||||
from string import ascii_lowercase as lower, digits, punctuation
|
from string import ascii_lowercase as lower, digits, punctuation
|
||||||
|
import sys
|
||||||
|
from loguru import logger as log
|
||||||
|
|
||||||
|
logger = log
|
||||||
|
logger.remove()
|
||||||
|
logger.add("logs/database.log", rotation="1 week", enqueue=True)
|
||||||
|
log.add(
|
||||||
|
"logs/application.log",
|
||||||
|
rotation="1 day",
|
||||||
|
compression="zip",
|
||||||
|
)
|
||||||
|
|
||||||
|
# logger.add(sys.stderr, format="{time} {level} {message}", level="INFO")
|
||||||
|
logger.add(sys.stdout)
|
||||||
|
|
||||||
|
|
||||||
ascii_lowercase = lower + digits + punctuation
|
ascii_lowercase = lower + digits + punctuation
|
||||||
@@ -204,6 +218,7 @@ class Database:
|
|||||||
app_id (str): The apparat id where the book should be added to
|
app_id (str): The apparat id where the book should be added to
|
||||||
prof_id (str): The id of the professor where the book should be added to.
|
prof_id (str): The id of the professor where the book should be added to.
|
||||||
"""
|
"""
|
||||||
|
logger.info(f"Adding book {bookdata.signature} to database")
|
||||||
if app_id is None or prof_id is None:
|
if app_id is None or prof_id is None:
|
||||||
raise ValueError("Apparate ID or Prof ID is None")
|
raise ValueError("Apparate ID or Prof ID is None")
|
||||||
conn = self.connect()
|
conn = self.connect()
|
||||||
@@ -387,7 +402,7 @@ class Database:
|
|||||||
|
|
||||||
def getBooks(
|
def getBooks(
|
||||||
self, app_id: Union[str, int], prof_id: Union[str, int], deleted=0
|
self, app_id: Union[str, int], prof_id: Union[str, int], deleted=0
|
||||||
) -> list[dict[int, BookData, int]]:
|
) -> list[dict[str, Union[BookData, int]]]:
|
||||||
"""
|
"""
|
||||||
Get the Books based on the apparat id and the professor id
|
Get the Books based on the apparat id and the professor id
|
||||||
|
|
||||||
@@ -406,14 +421,14 @@ class Database:
|
|||||||
if qdata is None:
|
if qdata is None:
|
||||||
return []
|
return []
|
||||||
for result_a in qdata:
|
for result_a in qdata:
|
||||||
data = {"id": int, "bookdata": BookData, "available": int}
|
data: dict[str, Any] = {"id": int, "bookdata": BookData, "available": int}
|
||||||
data["id"] = result_a[0]
|
data["id"] = result_a[0]
|
||||||
data["bookdata"] = load_pickle(result_a[1])
|
data["bookdata"] = load_pickle(result_a[1])
|
||||||
data["available"] = result_a[2]
|
data["available"] = result_a[2]
|
||||||
ret_result.append(data)
|
ret_result.append(data)
|
||||||
return ret_result
|
return ret_result
|
||||||
|
|
||||||
def updateBookdata(self, book_id, bookdata: BookData):
|
def updateBookdata(self, book_id: int, bookdata: BookData):
|
||||||
"""
|
"""
|
||||||
Update the bookdata in the database
|
Update the bookdata in the database
|
||||||
|
|
||||||
@@ -1183,7 +1198,7 @@ class Database:
|
|||||||
"UPDATE user SET password=? WHERE username=?", (new_password, user)
|
"UPDATE user SET password=? WHERE username=?", (new_password, user)
|
||||||
)
|
)
|
||||||
|
|
||||||
def getRole(self, user):
|
def getRole(self, user: str) -> str:
|
||||||
"""get the role of the user
|
"""get the role of the user
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
@@ -1510,7 +1525,7 @@ class Database:
|
|||||||
else:
|
else:
|
||||||
return []
|
return []
|
||||||
|
|
||||||
def getProfId(self, profdata: dict | Prof):
|
def getProfId(self, profdata: dict[str, Any] | Prof):
|
||||||
"""Get the prof ID based on the profdata
|
"""Get the prof ID based on the profdata
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
|
|||||||
Reference in New Issue
Block a user