Skip to content

Commit

Permalink
Carried out the merger of two loggers
Browse files Browse the repository at this point in the history
  • Loading branch information
Nakama3942 committed Apr 10, 2023
1 parent 1481930 commit 9b0b40b
Show file tree
Hide file tree
Showing 7 changed files with 549 additions and 339 deletions.
184 changes: 108 additions & 76 deletions qt_colored_logger/basic/basic_logger.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,43 +56,59 @@ def __init__(
self._system_architecture = platform.architecture()
self._pc_machine = platform.machine()

def _initialized_data(self, colors: list[str, str]) -> str:
def _initialized_data(
self,
colors: list[str, str],
html_environment: bool = False
) -> str:
"""
A method that assemble an entry of system initialized data.
Forms a console string.
:param colors: Color string list of initialized data
:return: a string with initialized data
"""
return (
f"{colors[1]}" +
f"{colors[0]}-{self._program_name}?entry> " +
f"${self._pc_name}^{self._user_name}" +
f"@{self._system_name}" +
f":{self._system_version}" +
f":{self._system_architecture[0]}" +
f":{self._system_architecture[1]}" +
f":{self._pc_machine}{GetAnsiFormat('reset/on')}"
)
if html_environment:
return (
f"<span style='background-color: #{colors[1]};'>" +
f"<span style='color: #{colors[0]};'>-{self._program_name}?entry> " +
f"${self._pc_name}^{self._user_name}" +
f"@{self._system_name}" +
f":{self._system_version}" +
f":{self._system_architecture[0]}" +
f":{self._system_architecture[1]}" +
f":{self._pc_machine}</span></span><br>"
)
else:
return (
f"{colors[1]}" +
f"{colors[0]}-{self._program_name}?entry> " +
f"${self._pc_name}^{self._user_name}" +
f"@{self._system_name}" +
f":{self._system_version}" +
f":{self._system_architecture[0]}" +
f":{self._system_architecture[1]}" +
f":{self._pc_machine}{GetAnsiFormat('reset/on')}"
)

def _html_initialized_data(self, colors: list[str, str]) -> str:
"""
A method that assemble an entry of system initialized data.
Forms an HTML string.
:param colors: Color string list of initialized data
:return: a string with initialized data
"""
return (
f"<span style='background-color: #{colors[1]};'>" +
f"<span style='color: #{colors[0]};'>-{self._program_name}?entry> " +
f"${self._pc_name}^{self._user_name}" +
f"@{self._system_name}" +
f":{self._system_version}" +
f":{self._system_architecture[0]}" +
f":{self._system_architecture[1]}" +
f":{self._pc_machine}</span></span><br>"
)
# def _html_initialized_data(self, colors: list[str, str]) -> str:
# """
# A method that assemble an entry of system initialized data.
# Forms an HTML string.
#
# :param colors: Color string list of initialized data
# :return: a string with initialized data
# """
# return (
# f"<span style='background-color: #{colors[1]};'>" +
# f"<span style='color: #{colors[0]};'>-{self._program_name}?entry> " +
# f"${self._pc_name}^{self._user_name}" +
# f"@{self._system_name}" +
# f":{self._system_version}" +
# f":{self._system_architecture[0]}" +
# f":{self._system_architecture[1]}" +
# f":{self._pc_machine}</span></span><br>"
# )

def _assemble_entry(
self,
Expand All @@ -103,6 +119,7 @@ def _assemble_entry(
bold: bool,
italic: bool,
invert: bool,
html_environment: bool = False
) -> str:
"""
A method that assemble an entry into a string and returns it.
Expand All @@ -117,51 +134,66 @@ def _assemble_entry(
:param invert: invert the colors in format the entry
:return: the formed entry string
"""
return (
(f"{GetAnsiFormat('bold/on')}" if bold else "") +
(f"{GetAnsiFormat('italic/on')}" if italic else "") +
(f"{GetAnsiFormat('invert/on')}" if invert else "") +
f"{colors[5]}" +
f"{colors[4]}-?entry> " +
(f"{colors[0]}*{datetime.datetime.now()} " if self.time else "") +
(f"{colors[1]}#STATUS: " if self.status else "") +
(f"{colors[2]}{status_message_text} " if self.status_message else "") +
(f"{colors[3]}{message_type} - " if self.status_type else "") +
(f"{colors[4]}{message_text}" if self.message else "") +
f"{GetAnsiFormat('reset/on')}"
)

def _assemble_html_entry(
self,
colors: list[str, str, str, str, str, str],
status_message_text: str,
message_type: str,
message_text: str,
bold: bool,
italic: bool,
) -> str:
"""
A method that assemble an entry into a string and returns it.
Forms an HTML string.
if html_environment:
return (
(f"<b>" if bold else "") +
(f"<i>" if italic else "") +
f"<span style='background-color: #{colors[5]};'>" +
f"<span style='color: #{colors[4]};'>-?entry> </span>" +
(f"<span style='color: #{colors[0]};'>*{datetime.datetime.now()} </span>" if self.time else "") +
(f"<span style='color: #{colors[1]};'>#STATUS: </span>" if self.status else "") +
(f"<span style='color: #{colors[2]};'>{status_message_text} </span>" if self.status_message else "") +
(f"<span style='color: #{colors[3]};'>{message_type} - </span>" if self.status_type else "") +
(f"<span style='color: #{colors[4]};'>{message_text}</span></span>" if self.message else "") +
(f"</i>" if italic else "") +
(f"</b>" if bold else "") + "<br>"
)
else:
return (
(f"{GetAnsiFormat('bold/on')}" if bold else "") +
(f"{GetAnsiFormat('italic/on')}" if italic else "") +
(f"{GetAnsiFormat('invert/on')}" if invert else "") +
f"{colors[5]}" +
f"{colors[4]}-?entry> " +
(f"{colors[0]}*{datetime.datetime.now()} " if self.time else "") +
(f"{colors[1]}#STATUS: " if self.status else "") +
(f"{colors[2]}{status_message_text} " if self.status_message else "") +
(f"{colors[3]}{message_type} - " if self.status_type else "") +
(f"{colors[4]}{message_text}" if self.message else "") +
f"{GetAnsiFormat('reset/on')}"
)

:param colors: 6 colors that the method uses to assemble the string
:param status_message_text: Status message
:param message_type: Entry type
:param message_text: Entry message
:param bold: Format the entry in bold
:param italic: Format the entry in italic
:return: the formed entry string
"""
return (
(f"<b>" if bold else "") +
(f"<i>" if italic else "") +
f"<span style='background-color: #{colors[5]};'>" +
f"<span style='color: #{colors[4]};'>-?entry> </span>" +
(f"<span style='color: #{colors[0]};'>*{datetime.datetime.now()} </span>" if self.time else "") +
(f"<span style='color: #{colors[1]};'>#STATUS: </span>" if self.status else "") +
(f"<span style='color: #{colors[2]};'>{status_message_text} </span>" if self.status_message else "") +
(f"<span style='color: #{colors[3]};'>{message_type} - </span>" if self.status_type else "") +
(f"<span style='color: #{colors[4]};'>{message_text}</span></span>" if self.message else "") +
(f"</i>" if italic else "") +
(f"</b>" if bold else "") + "<br>"
)
# def _assemble_html_entry(
# self,
# colors: list[str, str, str, str, str, str],
# status_message_text: str,
# message_type: str,
# message_text: str,
# bold: bool,
# italic: bool,
# ) -> str:
# """
# A method that assemble an entry into a string and returns it.
# Forms an HTML string.
#
# :param colors: 6 colors that the method uses to assemble the string
# :param status_message_text: Status message
# :param message_type: Entry type
# :param message_text: Entry message
# :param bold: Format the entry in bold
# :param italic: Format the entry in italic
# :return: the formed entry string
# """
# return (
# (f"<b>" if bold else "") +
# (f"<i>" if italic else "") +
# f"<span style='background-color: #{colors[5]};'>" +
# f"<span style='color: #{colors[4]};'>-?entry> </span>" +
# (f"<span style='color: #{colors[0]};'>*{datetime.datetime.now()} </span>" if self.time else "") +
# (f"<span style='color: #{colors[1]};'>#STATUS: </span>" if self.status else "") +
# (f"<span style='color: #{colors[2]};'>{status_message_text} </span>" if self.status_message else "") +
# (f"<span style='color: #{colors[3]};'>{message_type} - </span>" if self.status_type else "") +
# (f"<span style='color: #{colors[4]};'>{message_text}</span></span>" if self.message else "") +
# (f"</i>" if italic else "") +
# (f"</b>" if bold else "") + "<br>"
# )
2 changes: 1 addition & 1 deletion qt_colored_logger/logger/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,4 @@
"""

from .colored_logger import Logger
from .html_colored_logger import LoggerQ
# from .html_colored_logger import LoggerQ
Loading

0 comments on commit 9b0b40b

Please sign in to comment.