From 5a1169d8b8a05407cf8a5307c65b26584f835433 Mon Sep 17 00:00:00 2001 From: Fabio Manganiello Date: Wed, 2 Jan 2019 11:38:21 +0000 Subject: [PATCH] Wrapped stdout and stderr under the same application logger --- platypush/__init__.py | 4 ++++ platypush/logger.py | 17 +++++++++++++++++ 2 files changed, 21 insertions(+) create mode 100644 platypush/logger.py diff --git a/platypush/__init__.py b/platypush/__init__.py index 82a2343033..e5ed492da6 100644 --- a/platypush/__init__.py +++ b/platypush/__init__.py @@ -19,6 +19,7 @@ from .config import Config from .context import register_backends from .cron.scheduler import CronScheduler from .event.processor import EventProcessor +from .logger import Logger from .message.event import Event, StopEvent from .message.event.application import ApplicationStartedEvent, ApplicationStoppedEvent from .message.request import Request @@ -29,6 +30,7 @@ __author__ = 'Fabio Manganiello ' __version__ = '0.9.3' LOGGER = logging.getLogger(__name__) +LOGGER.setLevel(logging.INFO) class Daemon: """ Main class for the Platypush daemon """ @@ -171,6 +173,8 @@ def main(): Platypush daemon main """ + sys.stdout = Logger(LOGGER.info) + sys.stderr = Logger(LOGGER.warning) print('Starting platypush v.{}'.format(__version__)) app = Daemon.build_from_cmdline(sys.argv[1:]) app.start() diff --git a/platypush/logger.py b/platypush/logger.py new file mode 100644 index 0000000000..b764a1d05f --- /dev/null +++ b/platypush/logger.py @@ -0,0 +1,17 @@ +import sys + +class Logger: + def __init__(self, level): + self.level = level + + def write(self, message): + if isinstance(message, bytes): + message = message.decode() + if message and message != '\n': + self.level(message.rstrip()) + + def flush(self): + pass + + +# vim:sw=4:ts=4:et: