update logging facility in plugin API

This commit is contained in:
Rafal Makagon
2019-03-05 09:36:44 +01:00
committed by Paweł Kierski
parent 300ade5d43
commit 059a1ea343

View File

@@ -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")