mirror of
https://gitlab.com/crafty-controller/crafty-4.git
synced 2024-08-30 18:23:09 +00:00
Use local date and time formatting for Console
This commit is contained in:
@ -1,8 +1,10 @@
|
|||||||
import datetime
|
import datetime
|
||||||
import logging
|
import logging
|
||||||
import sys
|
import sys
|
||||||
|
import locale
|
||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
|
locale.setlocale(locale.LC_ALL, "") # Get the locale from the environment
|
||||||
|
|
||||||
try:
|
try:
|
||||||
from colorama import init
|
from colorama import init
|
||||||
@ -21,6 +23,11 @@ class Console:
|
|||||||
if "colorama" in sys.modules:
|
if "colorama" in sys.modules:
|
||||||
init()
|
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
|
@staticmethod
|
||||||
def do_print(message, color):
|
def do_print(message, color):
|
||||||
if "termcolor" in sys.modules or "colorama" in sys.modules:
|
if "termcolor" in sys.modules or "colorama" in sys.modules:
|
||||||
@ -54,30 +61,30 @@ class Console:
|
|||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def debug(message):
|
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}")
|
Console.magenta(f"[+] Crafty: {date_time} - DEBUG:\t{message}")
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def info(message):
|
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}")
|
Console.white(f"[+] Crafty: {date_time} - INFO:\t{message}")
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def warning(message):
|
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}")
|
Console.cyan(f"[+] Crafty: {date_time} - WARNING:\t{message}")
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def error(message):
|
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}")
|
Console.yellow(f"[+] Crafty: {date_time} - ERROR:\t{message}")
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def critical(message):
|
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}")
|
Console.red(f"[+] Crafty: {date_time} - CRITICAL:\t{message}")
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def help(message):
|
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}")
|
Console.green(f"[+] Crafty: {date_time} - HELP:\t{message}")
|
||||||
|
Reference in New Issue
Block a user