From 059a1ea3431cea762da02f01d03ffc5adf8702a9 Mon Sep 17 00:00:00 2001 From: Rafal Makagon Date: Tue, 5 Mar 2019 09:36:44 +0100 Subject: [PATCH] update logging facility in plugin API --- galaxy/api/plugin.py | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/galaxy/api/plugin.py b/galaxy/api/plugin.py index a7e35af..536f342 100644 --- a/galaxy/api/plugin.py +++ b/galaxy/api/plugin.py @@ -315,12 +315,23 @@ class Plugin(): async def get_game_times(self): raise NotImplementedError() -def create_and_run_plugin(plugin_class, argv): +def _prepare_logging(logger_file): root = logging.getLogger() root.setLevel(logging.DEBUG) - if len(argv) >= 4: - handler = logging.handlers.RotatingFileHandler(argv[3], "a", 10000000, 10) - root.addHandler(handler) + handler = logging.handlers.RotatingFileHandler( + logger_file, + mode="a", + maxBytes=10000000, + backupCount=10, + encoding="utf-8" + ) + formatter = logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s') + handler.setFormatter(formatter) + root.addHandler(handler) + +def create_and_run_plugin(plugin_class, argv): + logger_file = argv[3] if len(argv) >= 4 else "output.log" + _prepare_logging(logger_file) if len(argv) < 3: logging.critical("Not enough parameters, required: token, port")