feat(Spotify): Add logger

pull/250/head
Daniel Voogsgerd 2019-03-27 16:33:47 +01:00
parent ed358ef024
commit db69b449ba
1 changed files with 18 additions and 0 deletions

View File

@ -1,11 +1,14 @@
#!/usr/bin/env python3 #!/usr/bin/env python3
import argparse import argparse
import logging
import sys import sys
import signal import signal
import gi import gi
gi.require_version('Playerctl', '2.0') gi.require_version('Playerctl', '2.0')
from gi.repository import Playerctl, GLib from gi.repository import Playerctl, GLib
logger = logging.getLogger(__name__)
def on_play(player, status, manager): def on_play(player, status, manager):
on_metadata(player, player.props.metadata, manager) on_metadata(player, player.props.metadata, manager)
@ -56,11 +59,26 @@ def signal_handler(sig, frame):
def parse_arguments(): def parse_arguments():
parser = argparse.ArgumentParser() parser = argparse.ArgumentParser()
# Increase verbosity with every occurance of -v
parser.add_argument('-v', '--verbose', action="count", default=0)
return parser.parse_args() return parser.parse_args()
def main(): def main():
arguments = parse_arguments() arguments = parse_arguments()
# Initialize logging
logging.basicConfig(stream=sys.stderr, level=logging.DEBUG,
format='%(name)s %(levelname)s %(message)s')
# Logging is set by default to WARN and higher.
# With every occurance of -v it's lowered by one
logger.setLevel(max((3 - arguments.verbose) * 10, 0))
# Log the sent command line arguments
logger.debug('Arguments received {}'.format(vars(arguments)))
manager = Playerctl.PlayerManager() manager = Playerctl.PlayerManager()
loop = GLib.MainLoop() loop = GLib.MainLoop()