Commit 12a6ad85 authored by Martin Matějek's avatar Martin Matějek

Another small refactoring of logging

parent b5e9a6d3
......@@ -10,6 +10,7 @@ from .exceptions import (
NoSuchActionException,
NoSuchNotificationException,
NoSuchNotificationSkeletonException,
NotificationNotDismissibleException,
NotificationStorageException,
)
from .sorting import Sorting
......@@ -99,9 +100,9 @@ def print_notification(notification):
print("Metadata: {}".format(notification['metadata']))
# work-in-progress!
def setup_logging(loglevel=logging.INFO):
logging.basicConfig(level=loglevel, format='%(message)s')
logging_format = "%(levelname)s: %(message)s"
logging.basicConfig(level=loglevel, format=logging_format)
logger.setLevel(loglevel)
......@@ -112,6 +113,8 @@ def process_args(parser, args):
else:
setup_logging()
logger.debug("Argparser arguments: %s", args)
if args.config:
api = Api(os.path.abspath(args.config))
else:
......@@ -134,15 +137,14 @@ def process_args(parser, args):
if args.default_action:
opts['default_action'] = args.default_action
# still work-in-progress
try:
ret = api.create(**opts)
logger.info("Succesfully created notification '%s'", format(ret))
print("Succesfully created notification '{}'".format(ret))
except NoSuchNotificationSkeletonException:
logger.warning("'%s' is not valid notification template", args.template)
print("'{}' is not valid notification template".format(args.template))
sys.exit(1)
except NotificationStorageException as e:
logger.error("Failed to create notification. Reason: %s", e)
print("Failed to create notification. Reason: {}".format(e))
sys.exit(1)
elif args.command == 'list':
......@@ -171,17 +173,19 @@ def process_args(parser, args):
print_notification(ret)
except NoSuchNotificationException as e:
logger.warning(e)
print(e)
except MediaTypeNotAvailableException as e:
logger.warning(e)
print(e)
elif args.command == 'call':
try:
api.call_action(args.msgid, args.action, args.cmd_args)
except NoSuchNotificationException as e:
logger.warning(e)
print(e)
except NoSuchActionException as e:
logger.error("Failed to call action on notification: %s", e)
print("Failed to call action on notification: {}".format(e))
except NotificationNotDismissibleException:
print("This notification cannot be dismissed via dismiss action. Use another action instead.")
def main():
......
......@@ -66,7 +66,7 @@ class Api:
return rendered
raise NoSuchNotificationException("Notification ID '{}' does not exist".format(msgid))
raise NoSuchNotificationException("Notification with ID '{}' does not exist".format(msgid))
def get_templates(self):
"""Return notification types from plugins"""
......@@ -128,4 +128,4 @@ class Api:
self.notifications.remove(msgid)
else:
raise NoSuchNotificationException("Notification ID '{}' does not exist".format(msgid))
raise NoSuchNotificationException("Notification with ID '{}' does not exist".format(msgid))
......@@ -38,10 +38,10 @@ class Supervisor:
self.run_proc()
exit_code = self.join()
logger.info("Process exited with exit code %s", exit_code)
if exit_code != 0:
logger.info("stdout: %s", self.process.stdout.readline())
logger.warning("stderr: %s", self.process.stderr.readline())
logger.error("Process exited with exit code %s", exit_code)
logger.error("stdout: %s", self.process.stdout.readline())
logger.error("stderr: %s", self.process.stderr.readline())
sys.exit(0)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment