From 35be146498a258e78d99b0f5a42bbf60f39be047 Mon Sep 17 00:00:00 2001 From: Juligee <56492496+Juligee@users.noreply.github.com> Date: Thu, 28 Sep 2023 18:16:53 +0000 Subject: [PATCH] In doge_spin.py from the example file logging with intergrated with halo --- examples/doge_spin.py | 35 +++++++++++++++++++++++++++++++++-- 1 file changed, 33 insertions(+), 2 deletions(-) diff --git a/examples/doge_spin.py b/examples/doge_spin.py index f200c3e..67b82a9 100644 --- a/examples/doge_spin.py +++ b/examples/doge_spin.py @@ -6,21 +6,52 @@ import sys import time +# Import logger module +import logging + +# Store the logging on 'logfile.log' or display on the console +# The formatter codes range the level of alert and time of occurrence of log message +file_formatter = logging.Formatter('%(asctime)s~%(levelname)s~%(message)s~module:%(module)s~function:%(module)s') +console_formatter = logging.Formatter('%(levelname)s -- %(message)s') + +# The handler class determines where to log messages. +file_handler = logging.FileHandler("logfile.log") +file_handler.setLevel(logging.WARN) +file_handler.setFormatter(file_formatter) +console_handler = logging.StreamHandler() +console_handler.setLevel(logging.DEBUG) +console_handler.setFormatter(console_formatter) + +# Methods to interact with the logging system through class of instances +logger = logging.getLogger() +logger.addHandler(file_handler) +logger.addHandler(console_handler) +logger.setLevel(logging.DEBUG) + sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) +# Importing the Halo class from halo import Halo +# Halo Spin words and display emojis spinner = Halo(text='Such Spins', spinner='dots') +# If one or more emojis don't display correctly, +# logger both displays issue on console and log on "logfile.log" try: + logger.info("Start spinning process") spinner.start() - time.sleep(2) + time.sleep(2) spinner.text = 'Much Colors' spinner.color = 'magenta' time.sleep(2) - spinner.text = 'Very emojis' + spinner.cu = 'Very emojis' + print() + logger.critical(" 'Very emojis' did not work! ") spinner.spinner = 'hearts' time.sleep(2) spinner.stop_and_persist(symbol='🦄'.encode('utf-8'), text='Wow!') except (KeyboardInterrupt, SystemExit): spinner.stop() + +