Added write shortcuts.

This commit is contained in:
The Wobbler 2025-01-13 18:21:55 +01:00
parent 8e1b4ade13
commit def727006b

View file

@ -1,5 +1,6 @@
#!/usr/bin/python3
from os import PathLike
from .format import format_string
_msg_types_ncl = { # message types without colors
@ -24,7 +25,7 @@ class Log:
def __init__(
self,
log_path: str = None,
log_path: str | PathLike = None,
console_out: bool = True,
console_colored: bool = True,
file_colored: bool = True
@ -63,7 +64,47 @@ class Log:
logfile.write(logfile_msg)
logfile.close()
def format_msg(self, msg, msg_type: str="info", colored: bool=True, prefix: str=""):
def info(self, msg: str, prefix: str=""):
"""
Shortcut for Log.write(msg, "info", prefix)
:param msg: The message to be written.
:param prefix: An optional prefix that gets added at the beginning of the message.
"""
self.write(msg, "info", prefix)
def ok(self, msg: str, prefix: str):
"""
Shortcut for Log.write(msg, "ok", prefix)
:param msg: The message to be written.
:param prefix: An optional prefix that gets added at the beginning of the message.
"""
self.write(msg, "ok", prefix)
def warning(self, msg: str, prefix: str):
"""
Shortcut for Log.write(msg, "warning", prefix)
:param msg: The message to be written.
:param prefix: An optional prefix that gets added at the beginning of the message.
"""
self.write(msg, "warning", prefix)
def error(self, msg: str, prefix: str):
"""
Shortcut for Log.write(msg, "error", prefix)
:param msg: The message to be written.
:param prefix: An optional prefix that gets added at the beginning of the message.
"""
self.write(msg, "error", prefix)
def format_msg(self, msg: str, msg_type: str="info", colored: bool=True, prefix: str=""):
if colored:
formatted_msg = _msg_types[msg_type] + msg
formatted_msg += format_string("§rs")