From 115bfe4d3109439828d9cf9a5cdc2f0a644f6a91 Mon Sep 17 00:00:00 2001 From: trueold89 Date: Wed, 8 Nov 2023 00:52:13 +0300 Subject: [PATCH] Bugfix: logging system --- - now the time in the logs is parsed correctly - Timezone env added to dockerfile | docker-compose --- Dockerfile | 3 ++- Readme.md | 2 ++ bot/log.py | 20 ++++++++++---------- docker-compose.yml | 1 + 4 files changed, 15 insertions(+), 11 deletions(-) diff --git a/Dockerfile b/Dockerfile index 79038fe..30be724 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,9 +1,10 @@ FROM alpine:latest COPY bot /opt/bot -RUN apk update && apk add bash python3 py-pip wget icu-libs krb5-libs libgcc libintl libssl1.1 libstdc++ zlib && pip install telebot +RUN apk update && apk add tzdata bash python3 py-pip wget icu-libs krb5-libs libgcc libintl libssl1.1 libstdc++ zlib && pip install telebot RUN wget https://github.com/fedarovich/qbittorrent-cli/releases/download/v1.7.22315.1/qbt-linux-alpine-x64-1.7.22315.1.tar.gz && \ mkdir /opt/qbt && \ tar -zxf qbt-linux-alpine-x64-1.7.22315.1.tar.gz -C /opt/qbt && \ chmod a+x /opt/qbt/* && \ ln -sf /opt/qbt/qbt /bin/qbt && ln -sf /opt/bot/bot.py /bin/bot +RUN ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone ENTRYPOINT ["/bin/bot"] diff --git a/Readme.md b/Readme.md index be75444..0c87c4b 100644 --- a/Readme.md +++ b/Readme.md @@ -53,6 +53,7 @@ docker run \ -e QUSER="" \ -e QPASS="" \ -e LANG="YOUR_LANG" \ + -e TZ="Europe/Moscow" \ -d -it your_image_here ``` @@ -76,6 +77,7 @@ services: QUSER: "" QPASS: "" LANG: "" + TZ: "Europe/Moscow" ``` ```bash diff --git a/bot/log.py b/bot/log.py index e52f6ee..b52504f 100644 --- a/bot/log.py +++ b/bot/log.py @@ -12,7 +12,7 @@ def dt(): str = f'{date} | {time.strftime("%H:%M:%S")}' return str -DEFAULT = [f'{dt()} LOG: ',f'{dt()} ERROR: '] +DEFAULT = ['{} LOG: ','{} ERROR: '] ID = str(uuid.uuid1())[0:7] FILE = f'{ID}.txt' @@ -24,42 +24,42 @@ def file(log): logfile.close() def start(): - log1 = DEFAULT[0] + str(msg.get('l_create').format(FILE)) - log2 = DEFAULT[0] + str(msg.get('l_start')) + log1 = DEFAULT[0].format(dt()) + str(msg.get('l_create').format(FILE)) + log2 = DEFAULT[0].format(dt()) + str(msg.get('l_start')) file(log2) print(f'{log1}\n{log2}') def auth(name,id): - log = DEFAULT[0] + str(msg.get('l_auth').format(name,id)) + log = DEFAULT[0].format(dt()) + str(msg.get('l_auth').format(name,id)) file(log) print(log) def add(name,id,folder,path): - log = DEFAULT[0] + str(msg.get('l_add').format(name,id,folder,path)) + log = DEFAULT[0].format(dt()) + str(msg.get('l_add').format(name,id,folder,path)) file(log) print(log) def rm(name,id,folder): - log = DEFAULT[0] + str(msg.get('l_rm').format(name,id,folder)) + log = DEFAULT[0].format(dt()) + str(msg.get('l_rm').format(name,id,folder)) file(log) print(log) def addfile(name,id,filename): - log = DEFAULT[0] + str(msg.get('l_file').format(name,id,filename[9:])) + log = DEFAULT[0].format(dt()) + str(msg.get('l_file').format(name,id,filename[9:])) file(log) print(log) def addmagnet(name,id,link): - log = DEFAULT[0] + str(msg.get('l_magnet').format(name,id,link)) + log = DEFAULT[0].format(dt()) + str(msg.get('l_magnet').format(name,id,link)) file(log) print(log) def errqbt(): - log = DEFAULT[1] + str(msg.get('l_errqbt')) + log = DEFAULT[1].format(dt()) + str(msg.get('l_errqbt')) file(log) print(log) def errtelebot(): - log = DEFAULT[1] + str(msg.get('l_errtele')) + log = DEFAULT[1].format(dt()) + str(msg.get('l_errtele')) file(log) print(log) diff --git a/docker-compose.yml b/docker-compose.yml index 338bfe5..4325c57 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -14,3 +14,4 @@ services: QUSER: "" QPASS: "" LANG: "" + TZ: "Europe/Moscow"