Added write shortcuts.
This commit is contained in:
parent
8e1b4ade13
commit
def727006b
1 changed files with 43 additions and 2 deletions
|
@ -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")
|
||||
|
|
Loading…
Reference in a new issue