From ec590240c0b5816085f29df59f105be39251c4d9 Mon Sep 17 00:00:00 2001 From: misyaguziya <53165965+misyaguziya@users.noreply.github.com> Date: Fri, 31 Jan 2025 13:11:45 +0900 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B[bugfix]=20Utils=20:=20logger?= =?UTF-8?q?=E3=81=AE=E3=83=95=E3=82=A1=E3=82=A4=E3=83=AB=E5=AE=B9=E9=87=8F?= =?UTF-8?q?=E3=82=92=E5=88=B6=E9=99=90(10MB=E3=81=BE=E3=81=A7)=E3=80=81?= =?UTF-8?q?=E3=83=AD=E3=83=BC=E3=83=86=E3=83=BC=E3=82=B7=E3=83=A7=E3=83=B3?= =?UTF-8?q?=E3=81=A8=E3=81=97=E3=81=A6xxx.log=E3=81=A8xxx.log.1=E3=82=92?= =?UTF-8?q?=E7=94=9F=E6=88=90=E3=81=99=E3=82=8B=E3=82=88=E3=81=86=E3=81=AB?= =?UTF-8?q?=E5=A4=89=E6=9B=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src-python/utils.py | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src-python/utils.py b/src-python/utils.py index 8e23af38..67ef2859 100644 --- a/src-python/utils.py +++ b/src-python/utils.py @@ -3,6 +3,7 @@ from typing import Any import json import traceback import logging +from logging.handlers import RotatingFileHandler from ctranslate2 import get_supported_compute_types @@ -31,8 +32,17 @@ def setupLogger(name, log_file, level=logging.INFO): logger.setLevel(level) logger.propagate = False # 親ロガーへの伝播を防ぐ + # filled with 10MB logs + max_log_size = 10 * 1024 * 1024 # 10MB + # ハンドラーを作成 - file_handler = logging.FileHandler(log_file, encoding="utf-8", delay=True) + file_handler = RotatingFileHandler( + log_file, + maxBytes=max_log_size, + backupCount=1, + encoding="utf-8", + delay=True + ) file_handler.setLevel(level) # フォーマッターを設定