ripensamenti sui file di configurazione, il logger legge un file
separato
This commit is contained in:
@@ -3,46 +3,52 @@ 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:
|
||||||
colorama.init(convert=True)
|
with open(filepath, 'r') as fp:
|
||||||
self.LRED = colorama.Fore.LIGHTRED_EX
|
settings = json.load(fp)
|
||||||
self.RED = colorama.Fore.RED
|
fp.close()
|
||||||
self.LYELLOW = colorama.Fore.LIGHTYELLOW_EX
|
colorama.init(convert=True)
|
||||||
self.YELLOW = colorama.Fore.YELLOW
|
self.LRED = colorama.Fore.LIGHTRED_EX
|
||||||
self.LBLUE = colorama.Fore.LIGHTBLUE_EX
|
self.RED = colorama.Fore.RED
|
||||||
self.BLUE = colorama.Fore.BLUE
|
self.LYELLOW = colorama.Fore.LIGHTYELLOW_EX
|
||||||
self.LGREEN = colorama.Fore.LIGHTGREEN_EX
|
self.YELLOW = colorama.Fore.YELLOW
|
||||||
self.LGREEN = colorama.Fore.GREEN
|
self.LBLUE = colorama.Fore.LIGHTBLUE_EX
|
||||||
self.WHITE = colorama.Fore.LIGHTWHITE_EX
|
self.BLUE = colorama.Fore.BLUE
|
||||||
self.RST = colorama.Style.RESET_ALL
|
self.LGREEN = colorama.Fore.LIGHTGREEN_EX
|
||||||
|
self.LGREEN = colorama.Fore.GREEN
|
||||||
|
self.WHITE = colorama.Fore.LIGHTWHITE_EX
|
||||||
|
self.RST = colorama.Style.RESET_ALL
|
||||||
|
|
||||||
# Setup Logger
|
# Setup Logger
|
||||||
self.LOGGER = logging.getLogger(name)
|
self.LOGGER = logging.getLogger(name)
|
||||||
self.LOGGER.setLevel(logging.DEBUG)
|
self.LOGGER.setLevel(logging.DEBUG)
|
||||||
self.LOGGER.propagate = False
|
self.LOGGER.propagate = False
|
||||||
FORMATTER = logging.Formatter((settings["logFormat"]), (settings["logTimeFormat"]))
|
FORMATTER = logging.Formatter((settings["logFormat"]), (settings["logTimeFormat"]))
|
||||||
if fileLog:
|
if fileLog:
|
||||||
# File Logging
|
# File Logging
|
||||||
fh = logging.FileHandler((settings["logFile"]))
|
fh = logging.FileHandler((settings["logFile"]))
|
||||||
fh.setLevel(logging.DEBUG)
|
fh.setLevel(logging.DEBUG)
|
||||||
fh.setFormatter(FORMATTER)
|
fh.setFormatter(FORMATTER)
|
||||||
self.LOGGER.addHandler(fh)
|
self.LOGGER.addHandler(fh)
|
||||||
if consoleLog:
|
if consoleLog:
|
||||||
# Console Logging
|
# Console Logging
|
||||||
cl= logging.StreamHandler(sys.stdout)
|
cl= logging.StreamHandler(sys.stdout)
|
||||||
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"):
|
||||||
|
|||||||
5
bananaSPLIT/libbananasplit/loggerconf.json
Normal file
5
bananaSPLIT/libbananasplit/loggerconf.json
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
{
|
||||||
|
"logFile": "D:\\Test\\bananaSPLIT.log",
|
||||||
|
"logFormat": "%(asctime)s|%(levelname)-8s| %(message)-50s",
|
||||||
|
"logTimeFormat": "%m-%d %H:%M:%S"
|
||||||
|
}
|
||||||
@@ -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": {
|
||||||
|
|||||||
Reference in New Issue
Block a user