98 lines
1.9 KiB
Python
98 lines
1.9 KiB
Python
|
from datetime import datetime
|
||
|
from colors import *
|
||
|
from platform import system
|
||
|
import inspect
|
||
|
import json, os, config
|
||
|
|
||
|
|
||
|
__DEBUGGING_ALERT = False
|
||
|
|
||
|
MUSTDIE = system().lower() == 'windows'
|
||
|
LINUX = system().lower() == 'linux'
|
||
|
MACOS = system().lower() == 'darwin'
|
||
|
|
||
|
|
||
|
class CONF():
|
||
|
def __init__(self):
|
||
|
CONF.config = json.load(open('config.json'))
|
||
|
|
||
|
|
||
|
@staticmethod
|
||
|
def get(*params):
|
||
|
conf = CONF.config
|
||
|
|
||
|
for param in params:
|
||
|
if param in conf.keys():
|
||
|
conf = conf[param]
|
||
|
|
||
|
if conf:
|
||
|
return conf
|
||
|
|
||
|
return False
|
||
|
|
||
|
CONF()
|
||
|
|
||
|
|
||
|
def __GET_TIME():
|
||
|
return datetime.now().strftime("%H:%M:%S.%f")
|
||
|
|
||
|
|
||
|
def __GET_DATE():
|
||
|
return datetime.now().strftime("%Y-%m-%d")
|
||
|
|
||
|
|
||
|
def __ADD_TO_LOG(str):
|
||
|
if CONF.get('logging'):
|
||
|
if not os.path.isdir('log'):
|
||
|
os.mkdir('log')
|
||
|
log = open(f'log/{__GET_DATE()}.log', 'a')
|
||
|
log.write(str + '\n')
|
||
|
log.close()
|
||
|
|
||
|
|
||
|
def __PRINT_LOG(str, log):
|
||
|
if CONF.get('debug') and config.DEBUGGING:
|
||
|
st = inspect.stack()[2]
|
||
|
caller = st.filename.split('/')[-1].split('.')[0]
|
||
|
callerline = st.lineno
|
||
|
str = f'[{__GET_TIME()}] [{caller}:{callerline}] {str}'
|
||
|
log = f'[{caller}:{callerline}] {log}'
|
||
|
else:
|
||
|
str = f'[{__GET_TIME()}] {str}'
|
||
|
|
||
|
print(str)
|
||
|
__ADD_TO_LOG(log)
|
||
|
|
||
|
|
||
|
def INFO(s = ''):
|
||
|
__PRINT_LOG(f"[INFO] {str(s)}{RESET}", str(s))
|
||
|
|
||
|
|
||
|
def DEBUG(s = ''):
|
||
|
global __DEBUGGING_ALERT
|
||
|
|
||
|
if not CONF.get('debug'):
|
||
|
return None
|
||
|
|
||
|
if config.DEBUGGING:
|
||
|
__PRINT_LOG(f"{MAGENTA}[DEBUG]{RESET} {BGBLUE}{YELLOW}{BOLD}{str(s)}{RESET}", str(s))
|
||
|
elif not __DEBUGGING_ALERT:
|
||
|
WARN('DEBUGGING DISABLED BY OWNER!')
|
||
|
__DEBUGGING_ALERT = True
|
||
|
|
||
|
|
||
|
def SUCC(s = ''):
|
||
|
__PRINT_LOG(f"{GREEN}[SUCCESS]{RESET} {GREEN}{str(s)}{RESET}", str(s))
|
||
|
|
||
|
|
||
|
def WARN(s = ''):
|
||
|
__PRINT_LOG(f"{YELLOW}[WARN]{RESET} {YELLOW}{str(s)}{RESET}", str(s))
|
||
|
|
||
|
|
||
|
def ERR(s = ''):
|
||
|
__PRINT_LOG(f"{RED}[ERROR]{RESET} {RED}{str(s)}{RESET}", str(s))
|
||
|
|
||
|
|
||
|
def CRIT(s = ''):
|
||
|
__PRINT_LOG(f"{RED}{BOLD}[CRITICAL]{RESET} {BGRED}{WHITE} {str(s)} {RESET}", str(s))
|