Skip to content

Commit

Permalink
Added a new type category: Timer, and 3 entries for it
Browse files Browse the repository at this point in the history
  • Loading branch information
Nakama3942 committed Jun 18, 2023
1 parent 51df9d6 commit 6a4dd77
Show file tree
Hide file tree
Showing 6 changed files with 218 additions and 6 deletions.
5 changes: 5 additions & 0 deletions docs/DATA.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,10 @@ The library stores various important data for use that you may need to know whil
- milestone (v0.6.0)
- success
- fail
- Timer (^)
- start_timer (v0.6.1)
- timer_mark (v0.6.1)
- stop_timer (v0.6.1)

###### Settings:
- Global:
Expand Down Expand Up @@ -121,6 +125,7 @@ The library stores various important data for use that you may need to know whil
- @ - type: Message
- ! - type: Error
- & - type: Process
- ^ - type: Timer
- $ - free
- ^ - free
-->
Expand Down
186 changes: 182 additions & 4 deletions mighty_logger/powerful_logger.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ def __init__(
self._progress_start: datetime | None = None
self._progress_time: str = " "
self._progress_interrupt = False
self._start_timer_value: datetime | None = None
self.global_background = global_background
self._color_scheme_init()
if self._environment == LogEnvironments.CONSOLE:
Expand Down Expand Up @@ -262,6 +263,27 @@ def _color_scheme_init(self) -> None:
self._ColorScheme['TYPE_FAIL'] = [AnsiColor('FIREBRICK', "foreground"), AnsiColor('YELLOW', "foreground")]
self._ColorScheme['FAIL_MESSAGE'] = [AnsiColor('DARKRED', "foreground"), AnsiColor('DARKYELLOW', "foreground")]
self._ColorScheme['FAIL_BACKGROUND'] = ["", AnsiColor('DARKRED', "background")]
# START_TIMER colors
self._ColorScheme['START_TIMER_TIME'] = [AnsiColor('ORCHID', "foreground"), AnsiColor('LAVENDERBLUSH', "foreground")]
self._ColorScheme['START_TIMER_STATUS'] = [AnsiColor('ORANGE', "foreground"), AnsiColor('CHARTREUSE', "foreground")]
self._ColorScheme['START_TIMER_STATUS_MESSAGE'] = [AnsiColor('DARKORANGE', "foreground"), AnsiColor('LAWNGREEN', "foreground")]
self._ColorScheme['TYPE_START_TIMER'] = [AnsiColor('SEAGREEN', "foreground"), AnsiColor('PALEGREEN', "foreground")]
self._ColorScheme['START_TIMER_MESSAGE'] = [AnsiColor('FORESTGREEN', "foreground"), AnsiColor('LIGHTGREEN', "foreground")]
self._ColorScheme['START_TIMER_BACKGROUND'] = ["", AnsiColor('FORESTGREEN', "background")]
# TIMER_MARK colors
self._ColorScheme['TIMER_MARK_TIME'] = [AnsiColor('ORCHID', "foreground"), AnsiColor('DARKMAGENTA', "foreground")]
self._ColorScheme['TIMER_MARK_STATUS'] = [AnsiColor('ORANGE', "foreground"), AnsiColor('DARKRED', "foreground")]
self._ColorScheme['TIMER_MARK_STATUS_MESSAGE'] = [AnsiColor('DARKORANGE', "foreground"), AnsiColor('MAROON', "foreground")]
self._ColorScheme['TYPE_TIMER_MARK'] = [AnsiColor('KHAKI', "foreground"), AnsiColor('SIENNA', "foreground")]
self._ColorScheme['TIMER_MARK_MESSAGE'] = [AnsiColor('DARKKHAKI', "foreground"), AnsiColor('SADDLEBROWN', "foreground")]
self._ColorScheme['TIMER_MARK_BACKGROUND'] = ["", AnsiColor('DARKKHAKI', "background")]
# STOP_TIMER colors
self._ColorScheme['STOP_TIMER_TIME'] = [AnsiColor('ORCHID', "foreground"), AnsiColor('PURPLE', "foreground")]
self._ColorScheme['STOP_TIMER_STATUS'] = [AnsiColor('ORANGE', "foreground"), AnsiColor('DARKRED', "foreground")]
self._ColorScheme['STOP_TIMER_STATUS_MESSAGE'] = [AnsiColor('DARKORANGE', "foreground"), AnsiColor('MAROON', "foreground")]
self._ColorScheme['TYPE_STOP_TIMER'] = [AnsiColor('LIGHTSKYBLUE', "foreground"), AnsiColor('NAVY', "foreground")]
self._ColorScheme['STOP_TIMER_MESSAGE'] = [AnsiColor('SKYBLUE', "foreground"), AnsiColor('MIDNIGHTBLUE', "foreground")]
self._ColorScheme['STOP_TIMER_BACKGROUND'] = ["", AnsiColor('SKYBLUE', "background")]
case LogEnvironments.HTML:
self._ColorScheme['INITIAL_COLOR'] = [HexColor('GOLD'), HexColor('INDIGO')]
self._ColorScheme['INITIAL_BACKGROUND'] = ["", HexColor('GOLD')]
Expand Down Expand Up @@ -412,6 +434,27 @@ def _color_scheme_init(self) -> None:
self._ColorScheme['TYPE_FAIL'] = [HexColor('FIREBRICK'), HexColor('YELLOW')]
self._ColorScheme['FAIL_MESSAGE'] = [HexColor('DARKRED'), HexColor('DARKYELLOW')]
self._ColorScheme['FAIL_BACKGROUND'] = ["", HexColor('DARKRED')]
# START_TIMER colors
self._ColorScheme['START_TIMER_TIME'] = [HexColor('ORCHID'), HexColor('LAVENDERBLUSH')]
self._ColorScheme['START_TIMER_STATUS'] = [HexColor('ORANGE'), HexColor('CHARTREUSE')]
self._ColorScheme['START_TIMER_STATUS_MESSAGE'] = [HexColor('DARKORANGE'), HexColor('LAWNGREEN')]
self._ColorScheme['TYPE_START_TIMER'] = [HexColor('SEAGREEN'), HexColor('PALEGREEN')]
self._ColorScheme['START_TIMER_MESSAGE'] = [HexColor('FORESTGREEN'), HexColor('LIGHTGREEN')]
self._ColorScheme['START_TIMER_BACKGROUND'] = ["", HexColor('FORESTGREEN')]
# TIMER_MARK colors
self._ColorScheme['TIMER_MARK_TIME'] = [HexColor('ORCHID'), HexColor('DARKMAGENTA')]
self._ColorScheme['TIMER_MARK_STATUS'] = [HexColor('ORANGE'), HexColor('DARKRED')]
self._ColorScheme['TIMER_MARK_STATUS_MESSAGE'] = [HexColor('DARKORANGE'), HexColor('MAROON')]
self._ColorScheme['TYPE_TIMER_MARK'] = [HexColor('KHAKI'), HexColor('SIENNA')]
self._ColorScheme['TIMER_MARK_MESSAGE'] = [HexColor('DARKKHAKI'), HexColor('SADDLEBROWN')]
self._ColorScheme['TIMER_MARK_BACKGROUND'] = ["", HexColor('DARKKHAKI')]
# STOP_TIMER colors
self._ColorScheme['STOP_TIMER_TIME'] = [HexColor('ORCHID'), HexColor('PURPLE')]
self._ColorScheme['STOP_TIMER_STATUS'] = [HexColor('ORANGE'), HexColor('DARKRED')]
self._ColorScheme['STOP_TIMER_STATUS_MESSAGE'] = [HexColor('DARKORANGE'), HexColor('MAROON')]
self._ColorScheme['TYPE_STOP_TIMER'] = [HexColor('LIGHTSKYBLUE'), HexColor('NAVY')]
self._ColorScheme['STOP_TIMER_MESSAGE'] = [HexColor('SKYBLUE'), HexColor('MIDNIGHTBLUE')]
self._ColorScheme['STOP_TIMER_BACKGROUND'] = ["", HexColor('SKYBLUE')]

def _initial_log(self) -> None:
"""
Expand Down Expand Up @@ -484,6 +527,12 @@ def buffer(self) -> TextBufferType:

#todo v0.7.1 сделать конвертер из Console в HTML и наоборот

# ######################################################################################## #
# #
# Entering to Logger #
# #
# ######################################################################################## #

def empty(
self,
*,
Expand Down Expand Up @@ -1004,6 +1053,12 @@ def unresolved(
if self._environment == LogEnvironments.CONSOLE:
self._buffer.update_console()

# ######################################################################################## #
# #
# Entering to Processes #
# #
# ######################################################################################## #

def start_indefinite_process(
self,
*,
Expand Down Expand Up @@ -1032,7 +1087,7 @@ def start_indefinite_process(

self._progress_start = datetime.now()
progress_stop = datetime.now()
self._progress_time = str(progress_stop - self._progress_start).split(".")[0] + " "
self._progress_time = "&" + str(progress_stop - self._progress_start).split(".")[0]
func = getattr(self, "_initiation", None)
args = {}
if status_message != StatusMessageType("..."):
Expand Down Expand Up @@ -1121,7 +1176,7 @@ def start_definite_process(

self._progress_start = datetime.now()
progress_stop = datetime.now()
self._progress_time = str(progress_stop - self._progress_start).split(".")[0] + " "
self._progress_time = "&" + str(progress_stop - self._progress_start).split(".")[0]
func = getattr(self, "_initiation", None)
args = {}
if status_message != StatusMessageType("..."):
Expand Down Expand Up @@ -1229,7 +1284,7 @@ def note_process(
last = self._buffer.pop()

progress_stop = datetime.now()
self._progress_time = str(progress_stop - self._progress_start).split(".")[0] + " "
self._progress_time = "&" + str(progress_stop - self._progress_start).split(".")[0]
func = getattr(self, entry_type, None)
args = {}
if status_message != StatusMessageType("..."):
Expand Down Expand Up @@ -1270,7 +1325,7 @@ def stop_process(
self._buffer.remove()

progress_stop = datetime.now()
self._progress_time = str(progress_stop - self._progress_start).split(".")[0] + " "
self._progress_time = "&" + str(progress_stop - self._progress_start).split(".")[0]
func = getattr(self, "_success", None) if self._progress_rise == 100 else getattr(self, "_fail", None)
args = {}
if status_message != StatusMessageType("..."):
Expand Down Expand Up @@ -1455,3 +1510,126 @@ def _fail(
)
if self._environment == LogEnvironments.CONSOLE:
self._buffer.update_console()

# ######################################################################################## #
# #
# Entering to Timer #
# #
# ######################################################################################## #

def start_timer(
self,
*,
status_message: StatusMessageType = StatusMessageType("..."),
message_text: str = "...",
local_background: bool = True,
local_settings: dict = None
) -> None:
"""
...
:param status_message: Log entry status message
:param message_text: Log entry message
:param local_background: Display entry with background?
:param local_settings: Dictionary of local entering settings
"""
self._start_timer_value = datetime.now()
stop_timer_value = datetime.now()
self._progress_time = "^" + str(stop_timer_value - self._start_timer_value).split(".")[0]

if local_settings is None:
local_settings = {}
if not 'italic' in local_settings:
local_settings["italic"] = True
self._buffer << self._assemble_entry(
[
self._ColorScheme['START_TIMER_TIME'][local_background],
self._ColorScheme['START_TIMER_STATUS'][local_background],
self._ColorScheme['START_TIMER_STATUS_MESSAGE'][local_background],
self._ColorScheme['TYPE_START_TIMER'][local_background],
self._ColorScheme['START_TIMER_MESSAGE'][local_background],
self._ColorScheme['START_TIMER_BACKGROUND'][local_background],
], self._progress_time, self._icon_set.start_timer, status_message.current_status_message, "^START TIMER", message_text, self._environment, local_settings
)
if self._environment == LogEnvironments.CONSOLE:
self._buffer.update_console()

self._progress_time = " "

def timer_mark(
self,
*,
status_message: StatusMessageType = StatusMessageType("..."),
message_text: str = "...",
local_background: bool = True,
local_settings: dict = None
) -> None:
"""
...
:param status_message: Log entry status message
:param message_text: Log entry message
:param local_background: Display entry with background?
:param local_settings: Dictionary of local entering settings
"""
stop_timer_value = datetime.now()
self._progress_time = "^" + str(stop_timer_value - self._start_timer_value).split(".")[0]

if local_settings is None:
local_settings = {}
if not 'italic' in local_settings:
local_settings["italic"] = True
self._buffer << self._assemble_entry(
[
self._ColorScheme['TIMER_MARK_TIME'][local_background],
self._ColorScheme['TIMER_MARK_STATUS'][local_background],
self._ColorScheme['TIMER_MARK_STATUS_MESSAGE'][local_background],
self._ColorScheme['TYPE_TIMER_MARK'][local_background],
self._ColorScheme['TIMER_MARK_MESSAGE'][local_background],
self._ColorScheme['TIMER_MARK_BACKGROUND'][local_background],
], self._progress_time, self._icon_set.timer_mark, status_message.current_status_message, "^TIMER MARK", message_text, self._environment, local_settings
)
if self._environment == LogEnvironments.CONSOLE:
self._buffer.update_console()

self._progress_time = " "

def stop_timer(
self,
*,
status_message: StatusMessageType = StatusMessageType("..."),
message_text: str = "...",
local_background: bool = True,
local_settings: dict = None
) -> None:
"""
...
:param status_message: Log entry status message
:param message_text: Log entry message
:param local_background: Display entry with background?
:param local_settings: Dictionary of local entering settings
"""
stop_timer_value = datetime.now()
self._progress_time = "^" + str(stop_timer_value - self._start_timer_value).split(".")[0]


if local_settings is None:
local_settings = {}
if not 'italic' in local_settings:
local_settings["italic"] = True
self._buffer << self._assemble_entry(
[
self._ColorScheme['STOP_TIMER_TIME'][local_background],
self._ColorScheme['STOP_TIMER_STATUS'][local_background],
self._ColorScheme['STOP_TIMER_STATUS_MESSAGE'][local_background],
self._ColorScheme['TYPE_STOP_TIMER'][local_background],
self._ColorScheme['STOP_TIMER_MESSAGE'][local_background],
self._ColorScheme['STOP_TIMER_BACKGROUND'][local_background],
], self._progress_time, self._icon_set.stop_timer, status_message.current_status_message, "^STOP TIMER", message_text, self._environment, local_settings
)
if self._environment == LogEnvironments.CONSOLE:
self._buffer.update_console()

self._start_timer_value = None
self._progress_time = " "
3 changes: 3 additions & 0 deletions mighty_logger/src/log_enums.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,3 +46,6 @@ class TypesEntries:
UNRESOLVED = 'unresolved'
ACHIEVEMENT = '_achievement'
MILESTONE = '_milestone'
START_TIMER = 'start_timer'
TIMER_MARK = 'timer_mark'
STOP_TIMER = 'stop_timer'
15 changes: 15 additions & 0 deletions mighty_logger/text/icon_set.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,9 @@ class IconSetType:
milestone = ''
success = ''
fail = ''
start_timer = ''
timer_mark = ''
stop_timer = ''

class EmptyIconSet(IconSetType):
...
Expand Down Expand Up @@ -70,6 +73,9 @@ class IconSet1(IconSetType):
milestone = '🔖'
success = '✔️'
fail = '❌'
start_timer = '⏰'
timer_mark = '⌚'
stop_timer = '⏲️'

class IconSet2(IconSetType):
"""
Expand All @@ -96,6 +102,9 @@ class IconSet2(IconSetType):
milestone = '🔖'
success = '🎉'
fail = '🚫'
start_timer = '🕑'
timer_mark = '🕕'
stop_timer = '🕙'

class IconSet3(IconSetType):
"""
Expand All @@ -122,6 +131,9 @@ class IconSet3(IconSetType):
milestone = '🎯'
success = '👍'
fail = '👎'
start_timer = '🟩'
timer_mark = '🟨'
stop_timer = '🟪'

class IconSet4(IconSetType):
"""
Expand All @@ -148,3 +160,6 @@ class IconSet4(IconSetType):
milestone = '🗺️'
success = '✅'
fail = '❎'
start_timer = '⏳'
timer_mark = '⏱️'
stop_timer = '⌛'
5 changes: 5 additions & 0 deletions test/test_console.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
logger = Logger(program_name="Installer", console_width=115, status_message_global_entry=False)

logger.message(message_text="Program installation started")
logger.start_timer(message_text="Timer started")

sleep(1)
logger.start_indefinite_process(animation=IndefiniteAnimations.Star, message_text="File upload")
Expand All @@ -18,6 +19,7 @@
logger.stop_process(message_text="Files unzipped")

logger.warning(message_text="Newer version found")
logger.timer_mark(message_text="Timer mark", local_background=False)

sleep(1)
logger.start_definite_process(progress_bar=DefiniteAnimations.Dots, message_text="Installing files")
Expand All @@ -44,6 +46,7 @@
logger.note_process(entry_type=TypesEntries.MILESTONE, message_text="Files prepared")
sleep(3.7)
logger.progress_rise(76)
logger.note_process(entry_type=TypesEntries.TIMER_MARK, message_text="Timer mark")
sleep(1.5)
logger.progress_rise(77)
sleep(1.4)
Expand Down Expand Up @@ -77,4 +80,6 @@
sleep(1.3)
logger.stop_process(message_text="Program installed")

logger.stop_timer(message_text="Timer completed")

logger.buffer().save("log.txt")
Loading

0 comments on commit 6a4dd77

Please sign in to comment.