Skip to content

Commit f04fa58

Browse files
committed
Configure logging for CLI.
1 parent ec2af06 commit f04fa58

3 files changed

Lines changed: 9 additions & 12 deletions

File tree

src/modelbench/cli.py

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
import faulthandler
33
import io
44
import json
5-
import logging
65
import os
76

87
# silence Together's upgrade message, as the new library is not out of beta
@@ -14,25 +13,23 @@
1413
import sys
1514
from datetime import datetime, timezone
1615
from functools import wraps
16+
1717
import click
1818
import termcolor
1919
from click import echo
20+
from modellogger.log_config import configure_logging
2021
from rich.console import Console
2122
from rich.table import Table
2223

2324
import modelgauge.annotators.cheval.registration # noqa: F401
2425
from modelbench.benchmark_runner import BenchmarkRun, BenchmarkRunner, JsonRunTracker, TqdmRunTracker
2526
from modelbench.benchmarks import GeneralPurposeAiChatBenchmarkV1, SecurityBenchmark
26-
from modelbench.consistency_checker import (
27-
ConsistencyChecker,
28-
summarize_consistency_check_results,
29-
)
27+
from modelbench.consistency_checker import ConsistencyChecker, summarize_consistency_check_results
3028
from modelbench.record import dump_json
3129
from modelbench.standards import Standards
3230
from modelgauge.config import load_secrets_from_config, write_default_config
3331
from modelgauge.load_namespaces import load_namespaces
3432
from modelgauge.locales import DEFAULT_LOCALE, LOCALES
35-
from modellogger.log_config import get_logger
3633
from modelgauge.monitoring import PROMETHEUS
3734
from modelgauge.preflight import check_secrets, make_sut
3835
from modelgauge.prompt_sets import GENERAL_PROMPT_SETS, SECURITY_JAILBREAK_PROMPT_SETS
@@ -125,7 +122,7 @@ def cli() -> None:
125122
log_dir = pathlib.Path("run/logs")
126123
log_dir.mkdir(exist_ok=True, parents=True)
127124
filename = log_dir / f'modelbench-{datetime.now().strftime("%y%m%d-%H%M%S")}.log'
128-
logging.basicConfig(level=logging.DEBUG, handlers=[get_file_logging_handler(filename)], force=True)
125+
configure_logging(app_name="modelbench", log_file=filename)
129126
write_default_config()
130127
load_namespaces(disable_progress_bar=True)
131128

src/modelgauge/cli.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
import logging
21
import os
32
import pathlib
43
import warnings
54
from typing import Optional
65

76
import click
7+
from modellogger.log_config import get_logger
88

99
from modelgauge.annotator import Annotator
1010
from modelgauge.annotator_registry import ANNOTATORS
@@ -35,7 +35,7 @@
3535
from modelgauge.sut_registry import SUTS
3636
from modelgauge.test_registry import TESTS
3737

38-
logger = logging.getLogger(__name__)
38+
logger = get_logger(__name__)
3939

4040

4141
@cli.command(name="list")
@@ -338,8 +338,6 @@ def run_job(
338338
If running a SUT, the file must have 'UID' and 'Text' columns. The output will be saved to a CSV file.
339339
If running ONLY annotators, the file must have 'UID', 'Prompt', 'SUT', and 'Response' columns. The output will be saved to a json lines file.
340340
"""
341-
logging.basicConfig(level=logging.DEBUG if debug else logging.INFO)
342-
343341
# TODO: break this function up. It's branching too much
344342
# make sure the job has everything it needs to run
345343
secrets = load_secrets_from_config()

src/modelgauge/command_line.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
import sys
44

55
import click
6+
from modellogger.log_config import configure_logging
7+
68
from modelgauge.annotator_registry import ANNOTATORS
79
from modelgauge.cli_lazy import LOAD_ALL, LazyModuleImportGroup
810
from modelgauge.config import write_default_config
@@ -26,7 +28,7 @@
2628
def cli():
2729
"""Run the ModelGauge library from the command line."""
2830
# To add a command, decorate your function with @cli.command().
29-
31+
configure_logging(app_name="modelgauge")
3032
# Always create the config directory if it doesn't already exist.
3133
write_default_config()
3234

0 commit comments

Comments
 (0)