fix: typing, create log folder if missing

This commit is contained in:
əlemi 2023-11-02 05:32:21 +01:00
parent 82cd2fbf1d
commit 989731574a
Signed by: alemi
GPG key ID: A4895B84D311642C
2 changed files with 7 additions and 4 deletions

View file

@ -4,7 +4,7 @@ from typing import Dict
from termcolor import colored
def configure_logging(name:str, level=logging.INFO, color:bool = True):
def configure_logging(name:str, level=logging.INFO, color:bool = True, path:str = "log"):
import os
from logging.handlers import RotatingFileHandler
@ -27,7 +27,9 @@ def configure_logging(name:str, level=logging.INFO, color:bool = True):
logger = logging.getLogger()
logger.setLevel(level)
# create file handler which logs even debug messages
fh = RotatingFileHandler(f'log/{name}.log', maxBytes=1048576, backupCount=5) # 1MB files
if not os.path.isdir(path):
os.mkdir(path)
fh = RotatingFileHandler(f'{path}/{name}.log', maxBytes=1048576, backupCount=5) # 1MB files
fh.setLevel(logging.DEBUG)
# create console handler with a higher log level
ch = logging.StreamHandler()

View file

@ -34,7 +34,8 @@ class Treepuncher(
GameInventory,
GameContainer,
GameTablist,
GameWorld
GameWorld,
# GameMovement
):
name: str
storage: StorageDriver
@ -49,7 +50,7 @@ class Treepuncher(
def __init__(
self,
name: str,
config_file: str = None,
config_file: str = "",
**kwargs
):
self.ctx = dict()