ripensamenti sui file di configurazione, il logger legge un file

separato
This commit is contained in:
2019-12-18 19:35:24 +01:00
parent fd9434868f
commit 12501c4edc
3 changed files with 43 additions and 37 deletions

View File

@@ -3,17 +3,21 @@ Created on 2 nov 2019
@author: Emanuele Trabattoni @author: Emanuele Trabattoni
''' '''
import sys, os import sys
import json import json
import logging import logging
import colorama import colorama
from bananaSPLIT.main import fp
class fancyLogger(object): class fancyLogger(object):
''' '''
Colorizza il logger di python, per un' esperienza stile willy wonka Colorizza il logger di python, per un' esperienza stile willy wonka
''' '''
def __init__(self, name="Logger", consoleLog=True, fileLog=True): def __init__(self, filepath=None, name="Logger", consoleLog=True, fileLog=False):
settings = json.load(open(os.getcwd()+r"\libbananasplit\testEN.json"))["logger"] try:
with open(filepath, 'r') as fp:
settings = json.load(fp)
fp.close()
colorama.init(convert=True) colorama.init(convert=True)
self.LRED = colorama.Fore.LIGHTRED_EX self.LRED = colorama.Fore.LIGHTRED_EX
self.RED = colorama.Fore.RED self.RED = colorama.Fore.RED
@@ -43,6 +47,8 @@ class fancyLogger(object):
cl.setLevel(logging.DEBUG) cl.setLevel(logging.DEBUG)
cl.setFormatter(FORMATTER) cl.setFormatter(FORMATTER)
self.LOGGER.addHandler(cl) self.LOGGER.addHandler(cl)
except IOError as e:
print("Impossibile caricare la configurazione del logger: [{}]".format(e))
pass pass
def debug(self, msg="Undefined Debug"): def debug(self, msg="Undefined Debug"):

View File

@@ -0,0 +1,5 @@
{
"logFile": "D:\\Test\\bananaSPLIT.log",
"logFormat": "%(asctime)s|%(levelname)-8s| %(message)-50s",
"logTimeFormat": "%m-%d %H:%M:%S"
}

View File

@@ -1,10 +1,5 @@
{ {
"version": "v1.1a", "version": "v1.1a",
"logger": {
"logFile": "D:\\Test\\bananaSPLIT.log",
"logFormat": "%(asctime)s|%(levelname)-8s| %(message)-50s",
"logTimeFormat": "%m-%d %H:%M:%S"
},
"splitter": { "splitter": {
"name": "", "name": "",
"paths": { "paths": {