From def727006b51134312be3d475dc7fb17093e8742 Mon Sep 17 00:00:00 2001 From: EKNr1 Date: Mon, 13 Jan 2025 18:21:55 +0100 Subject: [PATCH] Added write shortcuts. --- wobbl_tools/text/log.py | 45 +++++++++++++++++++++++++++++++++++++++-- 1 file changed, 43 insertions(+), 2 deletions(-) diff --git a/wobbl_tools/text/log.py b/wobbl_tools/text/log.py index 622af59..0d2f6e1 100644 --- a/wobbl_tools/text/log.py +++ b/wobbl_tools/text/log.py @@ -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")