Skip to content

Commit ed95694

Browse files
authored
Merge pull request #288 from Venkat-Kunaparaju/thread-time
Optionally disable time/thread preamble in INFO level logging
2 parents b3f1c09 + bd674e1 commit ed95694

7 files changed

Lines changed: 49 additions & 4 deletions

File tree

.github/workflows/kind-tft.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ jobs:
1818
dpu_sim_config: config-kind.yaml
1919
- scenario: diverse-subset
2020
dpu_sim_config: config-kind.yaml
21+
tft_log_preamble: "false"
2122
- scenario: resource-limits
2223
dpu_sim_config: config-kind.yaml
2324
- scenario: dpu-offload
@@ -109,6 +110,7 @@ jobs:
109110
working-directory: dpu-simulator
110111
env:
111112
TFT_KUBECONFIG: ${{ github.workspace }}/dpu-simulator/kubeconfig/dpu-sim-host.kubeconfig
113+
TFT_LOG_PREAMBLE: ${{ matrix.tft_log_preamble }}
112114
run: |
113115
./bin/dpu-sim tft run \
114116
--config ${{ matrix.dpu_sim_config }} \

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -377,6 +377,9 @@ tft:
377377
- `TFT_EXTERNAL_SERVER_STRING` expected substring in the HTTP response body when
378378
`TFT_EXTERNAL_URL` is set. Defaults to `"The document has moved"` (the body of an HTTP 301
379379
redirect).
380+
- `TFT_LOG_PREAMBLE` enable or disable the timestamp and thread preamble that ktoolbox
381+
prepends to every log record. Defaults to `true`, which keeps the existing ktoolbox format.
382+
Set to `false` to strip the preamble and log only `LEVEL: message`.
380383

381384
## File Transfer via magic-wormhole
382385

evaluator.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ def parse_args() -> argparse.Namespace:
157157

158158
args = parser.parse_args()
159159

160-
common.log_config_logger(args.verbose, "tft", "ktoolbox")
160+
tftbase.configure_logging(args.verbose, "tft", "ktoolbox")
161161

162162
if args.config and not Path(args.config).exists():
163163
logger.error(f"No config file found at {args.config}, exiting")

generate_eval_config.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,7 @@ def parse_args() -> argparse.Namespace:
209209

210210
args = parser.parse_args()
211211

212-
common.log_config_logger(args.verbose, "tft", "ktoolbox")
212+
tftbase.configure_logging(args.verbose, "tft", "ktoolbox")
213213

214214
if args.tighten_only and not args.config:
215215
logger.error(

print_results.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ def parse_args() -> argparse.Namespace:
151151

152152
args = parser.parse_args()
153153

154-
common.log_config_logger(args.verbose, "tft", "ktoolbox")
154+
tftbase.configure_logging(args.verbose, "tft", "ktoolbox")
155155

156156
return args
157157

tft.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ def parse_args() -> argparse.Namespace:
9090

9191
args = parser.parse_args()
9292

93-
common.log_config_logger(args.verbosity, "tft", "ktoolbox")
93+
tftbase.configure_logging(args.verbosity, "tft", "ktoolbox")
9494

9595
if not Path(args.config).exists():
9696
raise ValueError("Must provide a valid config.yaml file (see config.yaml)")

tftbase.py

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import dataclasses
22
import functools
33
import json
4+
import logging
45
import math
56
import os
67
import re
@@ -12,6 +13,7 @@
1213
from pathlib import Path
1314
from typing import Any
1415
from typing import Optional
16+
from typing import Union
1517

1618
from ktoolbox import common
1719
from ktoolbox import host
@@ -36,13 +38,51 @@
3638
ENV_TFT_EXTERNAL_URL = "TFT_EXTERNAL_URL"
3739
ENV_TFT_EXTERNAL_SERVER_STRING = "TFT_EXTERNAL_SERVER_STRING"
3840

41+
ENV_TFT_LOG_PREAMBLE = "TFT_LOG_PREAMBLE"
42+
3943

4044
def get_environ(name: str) -> Optional[str]:
4145
# Some environment variables are honored as configuration.
4246
# Which ones? Run `git grep -w get_environ`!
4347
return common.getenv_config(name)
4448

4549

50+
def _get_log_preamble() -> bool:
51+
return common.str_to_bool(
52+
get_environ(ENV_TFT_LOG_PREAMBLE), on_default=True, on_error=True
53+
)
54+
55+
56+
def configure_logging(
57+
level: Optional[Union[int, bool, str]],
58+
*loggers: Union[str, logging.Logger],
59+
) -> None:
60+
# Wraps `common.log_config_logger` so the timestamp/thread preamble that
61+
# ktoolbox always prepends (e.g. "2026-01-01 07:39:38.957 INFO [th:123]:")
62+
# can be stripped via the TFT_LOG_PREAMBLE env var.
63+
# Default (true) preserves ktoolbox's built-in formatter.
64+
common.log_config_logger(level, *loggers)
65+
66+
if _get_log_preamble():
67+
return
68+
69+
formatter = logging.Formatter("%(levelname)-7s: %(message)s")
70+
71+
seen: set[int] = set()
72+
for lg in loggers:
73+
real_logger = common.ExtendedLogger.unwrap(lg)
74+
cur: Optional[logging.Logger] = real_logger
75+
while cur is not None:
76+
for h in cur.handlers:
77+
if id(h) in seen:
78+
continue
79+
seen.add(id(h))
80+
h.setFormatter(formatter)
81+
if not cur.propagate:
82+
break
83+
cur = cur.parent
84+
85+
4686
def _is_ib_test_type(test_type: "TestType") -> bool:
4787
"""Check if the test type requires RDMA/IB tools."""
4888
return test_type in (TestType.IB_WRITE_BW, TestType.IB_READ_BW, TestType.IB_SEND_BW)

0 commit comments

Comments
 (0)