Skip to content

Commit 8695c6f

Browse files
committed
Centralize logging configuration
1 parent e822a3f commit 8695c6f

File tree

4 files changed

+27
-3
lines changed

4 files changed

+27
-3
lines changed

app/logging.conf

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
[loggers]
2+
keys=root
3+
4+
[handlers]
5+
keys=stream_handler
6+
7+
[formatters]
8+
keys=formatter
9+
10+
[logger_root]
11+
level=DEBUG
12+
handlers=stream_handler
13+
14+
[handler_stream_handler]
15+
class=StreamHandler
16+
level=INFO
17+
formatter=formatter
18+
args=(sys.stderr,)
19+
20+
[formatter_formatter]
21+
format=[%(asctime)s] [%(name)s] [%(levelname)s] %(message)s

app/webservice.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
from typing import Union, Annotated
2525
import importlib.metadata
2626
import logging
27+
import logging.config
2728
import os
2829
import re
2930
import tempfile
@@ -40,7 +41,7 @@
4041
from .util import apierror
4142
from .worker import transcribe, detect_language as detect_language_task
4243

43-
logging.basicConfig(format='[%(asctime)s] [%(name)s] [%(levelname)s] %(message)s', level=logging.INFO, force=True)
44+
logging.config.fileConfig('app/logging.conf')
4445
logger = logging.getLogger(__name__)
4546

4647
APP_ENV = os.getenv("APP_ENV", "production")

app/whisper_cpp/core.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import logging
2+
import logging.config
23
import os
34
from io import StringIO
45
from threading import Lock
@@ -9,7 +10,7 @@
910
import json
1011
from .constants import ASR_ENGINE_OPTIONS
1112

12-
logging.basicConfig(format='[%(asctime)s] [%(name)s] [%(levelname)s] %(message)s', level=logging.INFO, force=True)
13+
logging.config.fileConfig('app/logging.conf')
1314
logger = logging.getLogger(__name__)
1415

1516
model_name = os.getenv("ASR_MODEL", "small")

app/worker.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import logging
2+
import logging.config
23
import os
34

45
from celery import Celery
@@ -8,7 +9,7 @@
89

910
from .util.audio import load_audio
1011

11-
logging.basicConfig(format='[%(asctime)s] [%(name)s] [%(levelname)s] %(message)s', level=logging.INFO, force=True)
12+
logging.config.fileConfig('app/logging.conf')
1213
logger = logging.getLogger(__name__)
1314

1415
# monkeypatch tqdm to fool whisper's `transcribe` function

0 commit comments

Comments
 (0)