Use local date and time formatting for Console

This commit is contained in:
luukas 2022-05-21 01:41:48 +03:00
parent d97bcc608f
commit eff7aefb6e
No known key found for this signature in database
GPG Key ID: CC4915E8D71FC044

View File

@ -1,8 +1,10 @@
import datetime
import logging
import sys
import locale
logger = logging.getLogger(__name__)
locale.setlocale(locale.LC_ALL, "") # Get the locale from the environment
try:
from colorama import init
@ -21,6 +23,11 @@ class Console:
if "colorama" in sys.modules:
init()
@staticmethod
def get_fmt_date_time():
# This will use the local date (%x) and time (%X) formatting
return datetime.datetime.now().strftime("%x %X")
@staticmethod
def do_print(message, color):
if "termcolor" in sys.modules or "colorama" in sys.modules:
@ -54,30 +61,30 @@ class Console:
@staticmethod
def debug(message):
date_time = datetime.datetime.now().strftime("%Y-%m-%d %I:%M:%S %p")
date_time = Console.get_fmt_date_time()
Console.magenta(f"[+] Crafty: {date_time} - DEBUG:\t{message}")
@staticmethod
def info(message):
date_time = datetime.datetime.now().strftime("%Y-%m-%d %I:%M:%S %p")
date_time = Console.get_fmt_date_time()
Console.white(f"[+] Crafty: {date_time} - INFO:\t{message}")
@staticmethod
def warning(message):
date_time = datetime.datetime.now().strftime("%Y-%m-%d %I:%M:%S %p")
date_time = Console.get_fmt_date_time()
Console.cyan(f"[+] Crafty: {date_time} - WARNING:\t{message}")
@staticmethod
def error(message):
date_time = datetime.datetime.now().strftime("%Y-%m-%d %I:%M:%S %p")
date_time = Console.get_fmt_date_time()
Console.yellow(f"[+] Crafty: {date_time} - ERROR:\t{message}")
@staticmethod
def critical(message):
date_time = datetime.datetime.now().strftime("%Y-%m-%d %I:%M:%S %p")
date_time = Console.get_fmt_date_time()
Console.red(f"[+] Crafty: {date_time} - CRITICAL:\t{message}")
@staticmethod
def help(message):
date_time = datetime.datetime.now().strftime("%Y-%m-%d %I:%M:%S %p")
date_time = Console.get_fmt_date_time()
Console.green(f"[+] Crafty: {date_time} - HELP:\t{message}")