Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

In doge_spin.py from the example file logging was integrated with halo #178

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 33 additions & 2 deletions examples/doge_spin.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()