mirror of https://gitlab.com/pamhyr/pamhyr2
Pamhyr: Add log file and some log display.
parent
ac12275d81
commit
475c9fb23c
|
|
@ -27,7 +27,8 @@ from PyQt5.QtWidgets import QApplication
|
||||||
|
|
||||||
from config import Config
|
from config import Config
|
||||||
from tools import (
|
from tools import (
|
||||||
reset_timers, display_timers, timer
|
reset_timers, display_timers, timer,
|
||||||
|
logger_color_blue, logger_color_red, logger_color_green, logger_color_reset
|
||||||
)
|
)
|
||||||
|
|
||||||
from View.MainWindow import ApplicationWindow
|
from View.MainWindow import ApplicationWindow
|
||||||
|
|
@ -35,12 +36,45 @@ from Model.Study import Study
|
||||||
|
|
||||||
logging.basicConfig(
|
logging.basicConfig(
|
||||||
level=logging.DEBUG,
|
level=logging.DEBUG,
|
||||||
format='[PAMHYR][%(levelname)s] %(message)s'
|
format=(f'[{logger_color_blue()}PAMHYR{logger_color_reset()}]' +
|
||||||
|
f'[{logger_color_green()}%(levelname)s{logger_color_reset()}]' +
|
||||||
|
' %(message)s')
|
||||||
)
|
)
|
||||||
logger = logging.getLogger()
|
logger = logging.getLogger()
|
||||||
logger.setLevel(logging.INFO)
|
logger.setLevel(logging.INFO)
|
||||||
|
|
||||||
|
try:
|
||||||
|
log = os.path.join(
|
||||||
|
os.path.dirname(Config.filename()), "log.txt"
|
||||||
|
)
|
||||||
|
logfile = open(log, "w+")
|
||||||
|
handler = logging.StreamHandler(logfile)
|
||||||
|
formatter = logging.Formatter('[%(asctime)s][%(levelname)s] %(message)s')
|
||||||
|
handler.setFormatter(formatter)
|
||||||
|
handler.setLevel(logging.DEBUG)
|
||||||
|
logger.addHandler(handler)
|
||||||
|
except:
|
||||||
|
logger.error("Failed to create logfile...")
|
||||||
|
|
||||||
def license():
|
def license():
|
||||||
|
blue = lambda s: logger.info(f"{logger_color_blue()}{s}{logger_color_reset()}")
|
||||||
|
|
||||||
|
blue("""`7MM\"""Mq. db `7MMM. ,MMF'`7MMF' `7MMF'`YMM' `MM'`7MM\"""Mq.""")
|
||||||
|
blue(""" MM `MM. ;MM: MMMb dPMM MM MM VMA ,V MM `MM.""")
|
||||||
|
blue(""" MM ,M9 ,V^MM. M YM ,M MM MM MM VMA ,V MM ,M9""")
|
||||||
|
blue(""" MMmmdM9 ,M `MM M Mb M' MM MMmmmmmmMM VMMP MMmmdM9""")
|
||||||
|
blue(""" MM AbmmmqMA M YM.P' MM MM MM MM MM YM.""")
|
||||||
|
blue(""" MM A' VML M `YM' MM MM MM MM MM `Mb.""")
|
||||||
|
blue(""".JMML. .AMA. .AMMA..JML. `' .JMML..JMML. .JMML. .JMML. .JMML. .JMM.""")
|
||||||
|
with open(os.path.abspath(
|
||||||
|
os.path.join(
|
||||||
|
os.path.dirname(__file__),
|
||||||
|
"VERSION"
|
||||||
|
)
|
||||||
|
), "r") as f:
|
||||||
|
version = f.readline().strip()
|
||||||
|
logger.info(f"version: {logger_color_green()}{version}{logger_color_reset()}")
|
||||||
|
|
||||||
logger.info("license: pamhyr Copyright (C) 2023 INRAE")
|
logger.info("license: pamhyr Copyright (C) 2023 INRAE")
|
||||||
logger.info("license: This program comes with ABSOLUTELY NO WARRANTY.")
|
logger.info("license: This program comes with ABSOLUTELY NO WARRANTY.")
|
||||||
logger.info("license: This is free software, and you are welcome to redistribute it")
|
logger.info("license: This is free software, and you are welcome to redistribute it")
|
||||||
|
|
|
||||||
24
src/tools.py
24
src/tools.py
|
|
@ -39,6 +39,30 @@ from functools import (
|
||||||
|
|
||||||
logger = logging.getLogger()
|
logger = logging.getLogger()
|
||||||
|
|
||||||
|
def logger_color_blue():
|
||||||
|
posix = os.name == "posix"
|
||||||
|
if posix:
|
||||||
|
return f"{Style.BRIGHT}{Fore.BLUE}"
|
||||||
|
return ""
|
||||||
|
|
||||||
|
def logger_color_red():
|
||||||
|
posix = os.name == "posix"
|
||||||
|
if posix:
|
||||||
|
return f"{Style.BRIGHT}{Fore.RED}"
|
||||||
|
return ""
|
||||||
|
|
||||||
|
def logger_color_green():
|
||||||
|
posix = os.name == "posix"
|
||||||
|
if posix:
|
||||||
|
return f"{Style.BRIGHT}{Fore.GREEN}"
|
||||||
|
return ""
|
||||||
|
|
||||||
|
def logger_color_reset():
|
||||||
|
posix = os.name == "posix"
|
||||||
|
if posix:
|
||||||
|
return f"{Style.RESET_ALL}"
|
||||||
|
return ""
|
||||||
|
|
||||||
##########
|
##########
|
||||||
# TIMERS #
|
# TIMERS #
|
||||||
##########
|
##########
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue