From 450d708887e205587aeaab0d807342fa6c665469 Mon Sep 17 00:00:00 2001 From: Martin Mares Date: Sat, 19 Feb 2022 22:51:12 +0100 Subject: [PATCH] Telegram: Logging via syslog --- telegram/burrow-telegram.py | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/telegram/burrow-telegram.py b/telegram/burrow-telegram.py index 11de929..be093b9 100755 --- a/telegram/burrow-telegram.py +++ b/telegram/burrow-telegram.py @@ -8,6 +8,7 @@ import asyncio_mqtt from configparser import ConfigParser from datetime import datetime, timedelta import logging +from logging.handlers import SysLogHandler import signal import ssl import sys @@ -16,10 +17,15 @@ config = ConfigParser() config.read('/usr/local/etc/burrow-telegram') API_TOKEN = config['telegram']['api_token'] CHATS = list(map(int, config['telegram']['chats'].split(' '))) - -# formatter = logging.Formatter(fmt="%(asctime)s %(name)s.%(levelname)s: %(message)s", datefmt='%Y-%m-%d %H:%M:%S') -formatter = logging.Formatter(fmt="%(message)s") # systemd will handle the rest -log_handler = logging.StreamHandler(stream=sys.stdout) +USE_SYSLOG = True + +if USE_SYSLOG: + formatter = logging.Formatter(fmt="%(message)s") # systemd will handle the rest + log_handler = SysLogHandler('/dev/log', facility=SysLogHandler.LOG_LOCAL1) + log_handler.ident = 'burrow-telegram: ' +else: + formatter = logging.Formatter(fmt="%(asctime)s %(name)s.%(levelname)s: %(message)s", datefmt='%Y-%m-%d %H:%M:%S') + log_handler = logging.StreamHandler(stream=sys.stdout) log_handler.setFormatter(formatter) logger = logging.getLogger() logger.setLevel(logging.INFO) -- 2.39.5