Skip to content

Commit 42a798e

Browse files
authored
Merge pull request #227 from AllenNeuralDynamics/refactor-logging-formatting
Refactor logging statements to use lazy formatting for consistency
2 parents b923c5d + ef9d6f8 commit 42a798e

File tree

8 files changed

+34
-34
lines changed

8 files changed

+34
-34
lines changed

docs/build.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -140,18 +140,18 @@ def copy_assets() -> None:
140140
dest: Path = DOCS_DIR / file_or_dir
141141

142142
if src.exists():
143-
log.info(f"Copying {file_or_dir} to docs...")
143+
log.info("Copying %s to docs...", file_or_dir)
144144

145145
if src.is_file():
146-
log.info(f"Copying file {src} to {dest}")
146+
log.info("Copying file %s to %s", src, dest)
147147
shutil.copy(src, dest)
148148
else:
149149
if dest.exists():
150150
shutil.rmtree(dest)
151151
shutil.copytree(src, dest)
152-
log.info(f"{file_or_dir} copied successfully.")
152+
log.info("%s copied successfully.", file_or_dir)
153153
else:
154-
log.warning(f"Source: {file_or_dir} not found, skipping.")
154+
log.warning("Source: %s not found, skipping.", file_or_dir)
155155

156156

157157
def find_service_settings_classes(src_dir: Path) -> List[Tuple[str, Optional[str]]]: # noqa: C901
@@ -201,7 +201,7 @@ def find_service_settings_classes(src_dir: Path) -> List[Tuple[str, Optional[str
201201
service_settings.append((node.name, yml_section))
202202

203203
except Exception as e:
204-
log.warning(f"Failed to parse {py_file}: {e}")
204+
log.warning("Failed to parse %s: %s", py_file, e)
205205

206206
return sorted(service_settings, key=lambda x: x[0])
207207

@@ -239,7 +239,7 @@ def generate_service_settings_table() -> None:
239239
with open(output_path, "w", encoding="utf-8") as f:
240240
f.write("\n".join(content))
241241

242-
log.info(f"Service settings documentation written to {output_path}")
242+
log.info("Service settings documentation written to %s", output_path)
243243

244244

245245
def main() -> None:

src/clabe/cache_manager.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ def get_instance(
163163
cache_data = CacheData.model_validate_json(f.read())
164164
instance.caches = cache_data.caches
165165
except Exception as e:
166-
logger.warning(f"Cache file {cache_path} is corrupted: {e}. Creating new instance.")
166+
logger.warning("Cache file %s is corrupted: %s. Creating new instance.", cache_path, e)
167167

168168
cls._instance = instance
169169

@@ -306,7 +306,7 @@ def cli_cmd(self):
306306
if not manager.caches:
307307
logger.info("No caches available.")
308308
for name, cache in manager.caches.items():
309-
logger.info(f"Cache '{name}': {cache.values}")
309+
logger.info("Cache '%s': %s", name, cache.values)
310310

311311

312312
class _ResetCacheCli(BaseSettings):

src/clabe/constants.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222

2323
for i, p in enumerate(KNOWN_CONFIG_FILES):
2424
if Path(p).exists():
25-
logger.debug(f"Found config file: {p} with rank priority {i}")
25+
logger.debug("Found config file: %s with rank priority %s", p, i)
2626

2727

2828
class ByAnimalFiles(enum.StrEnum):

src/clabe/pickers/_by_animal_modifier.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -135,12 +135,12 @@ def inject(self, rig: TRig) -> TRig:
135135
"""
136136
target_file = self._subject_db_path / f"{self._model_name}.json"
137137
if not target_file.exists():
138-
logger.warning(f"File not found: {target_file}. Using default.")
138+
logger.warning("File not found: %s. Using default.", target_file)
139139
else:
140140
target = rgetattr(rig, self._model_path)
141141
self._tp = TypeAdapter(type(target))
142142
deserialized = self._tp.validate_json(target_file.read_text(encoding="utf-8"))
143-
logger.info(f"Loading {self._model_name} from: {target_file}. Deserialized: {deserialized}")
143+
logger.info("Loading %s from: %s. Deserialized: %s", self._model_name, target_file, deserialized)
144144
self._process_before_inject(deserialized)
145145
rsetattr(rig, self._model_path, deserialized)
146146
return rig
@@ -165,11 +165,11 @@ def dump(self) -> None:
165165

166166
try:
167167
to_inject = self._process_before_dump()
168-
logger.info(f"Saving {self._model_name} to: {target_file}. Serialized: {to_inject}")
168+
logger.info("Saving %s to: %s. Serialized: %s", self._model_name, target_file, to_inject)
169169
target_folder.mkdir(parents=True, exist_ok=True)
170170
target_file.write_text(tp.dump_json(to_inject, indent=2).decode("utf-8"), encoding="utf-8")
171171
except Exception as e:
172-
logger.error(f"Failed to process before dumping modifier: {e}")
172+
logger.error("Failed to process before dumping modifier: %s", e)
173173
raise
174174

175175

src/clabe/xml_rpc/_client.py

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ def __init__(self, settings: XmlRpcClientSettings):
6262
self, timeout=settings.timeout, poll_interval=settings.poll_interval, monitor=settings.monitor
6363
)
6464

65-
logger.info(f"RPC client initialized for server: {settings.server_url}")
65+
logger.info("RPC client initialized for server: %s", settings.server_url)
6666

6767
def _call_with_auth(self, method_name: str, *args, **kwargs):
6868
"""
@@ -108,7 +108,7 @@ def submit_command(self, cmd_args: list[str] | str) -> JobSubmissionResponse:
108108
cmd_args = [cmd_args]
109109
result = self._call_with_auth("run", cmd_args)
110110
response = JobSubmissionResponse(**result)
111-
logger.info(f"Submitted command {cmd_args} with job ID: {response.job_id}")
111+
logger.info("Submitted command %s with job ID: %s", cmd_args, response.job_id)
112112
return response
113113

114114
def get_result(self, job_id: str) -> JobResult:
@@ -297,12 +297,12 @@ def upload_file(
297297
file_data = local_path.read_bytes()
298298
data_base64 = base64.b64encode(file_data).decode("utf-8")
299299

300-
logger.info(f"Uploading file {local_path} as {remote_filename} ({file_size} bytes)")
300+
logger.info("Uploading file %s as %s (%s bytes)", local_path, remote_filename, file_size)
301301

302302
result = self._call_with_auth("upload_file", remote_filename, data_base64, overwrite)
303303
response = FileUploadResponse(**result)
304304

305-
logger.info(f"Successfully uploaded {remote_filename}")
305+
logger.info("Successfully uploaded %s", remote_filename)
306306
return response
307307

308308
def upload_model(self, model: BaseModel, remote_filename: str, overwrite: bool = True) -> FileUploadResponse:
@@ -346,12 +346,12 @@ class MyModel(BaseModel):
346346
# Encode for transport
347347
data_base64 = base64.b64encode(json_bytes).decode("utf-8")
348348

349-
logger.info(f"Uploading model as {remote_filename} ({data_size} bytes)")
349+
logger.info("Uploading model as %s (%s bytes)", remote_filename, data_size)
350350

351351
result = self._call_with_auth("upload_file", remote_filename, data_base64, overwrite)
352352
response = FileUploadResponse(**result)
353353

354-
logger.info(f"Successfully uploaded model as {remote_filename}")
354+
logger.info("Successfully uploaded model as %s", remote_filename)
355355
return response
356356

357357
def download_file(self, remote_filename: str, local_path: Optional[Union[str, Path]] = None) -> Path:
@@ -376,7 +376,7 @@ def download_file(self, remote_filename: str, local_path: Optional[Union[str, Pa
376376
else:
377377
local_path = Path(local_path)
378378

379-
logger.info(f"Downloading file {remote_filename} to {local_path}")
379+
logger.info("Downloading file %s to %s", remote_filename, local_path)
380380

381381
result = self._call_with_auth("download_file", remote_filename)
382382

@@ -396,7 +396,7 @@ def download_file(self, remote_filename: str, local_path: Optional[Union[str, Pa
396396
file_data = response.data
397397
local_path.write_bytes(file_data)
398398

399-
logger.info(f"Successfully downloaded {remote_filename} ({response.size} bytes)")
399+
logger.info("Successfully downloaded %s (%s bytes)", remote_filename, response.size)
400400
return local_path
401401

402402
def list_files(self) -> list[FileInfo]:
@@ -432,10 +432,10 @@ def delete_file(self, remote_filename: str) -> FileDeleteResponse:
432432
print(f"Deleted: {result.filename}")
433433
```
434434
"""
435-
logger.info(f"Deleting file {remote_filename}")
435+
logger.info("Deleting file %s", remote_filename)
436436
result = self._call_with_auth("delete_file", remote_filename)
437437
response = FileDeleteResponse(**result)
438-
logger.info(f"Successfully deleted {remote_filename}")
438+
logger.info("Successfully deleted %s", remote_filename)
439439
return response
440440

441441
def delete_all_files(self) -> FileBulkDeleteResponse:
@@ -454,7 +454,7 @@ def delete_all_files(self) -> FileBulkDeleteResponse:
454454
logger.info("Deleting all files from server")
455455
result = self._call_with_auth("delete_all_files")
456456
response = FileBulkDeleteResponse(**result)
457-
logger.info(f"Successfully deleted {response.deleted_count} files")
457+
logger.info("Successfully deleted %s files", response.deleted_count)
458458
return response
459459

460460
def ping(self) -> bool:
@@ -477,7 +477,7 @@ def ping(self) -> bool:
477477
self.list_jobs()
478478
return True
479479
except (RuntimeError, ConnectionError, ValueError) as e:
480-
logger.warning(f"Server ping failed: {e}")
480+
logger.warning("Server ping failed: %s", e)
481481
return False
482482

483483
def __enter__(self):

src/clabe/xml_rpc/_executor.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ def __init__(
8181
self.poll_interval = poll_interval
8282
self.monitor = monitor
8383

84-
logger.info(f"RPC executor initialized for server: {client.settings.server_url}")
84+
logger.info("RPC executor initialized for server: %s", client.settings.server_url)
8585

8686
def run(self, command: Command[Any]) -> CommandResult:
8787
"""
@@ -105,13 +105,13 @@ def run(self, command: Command[Any]) -> CommandResult:
105105
print(f"Output: {result.stdout}")
106106
```
107107
"""
108-
logger.info(f"Executing command via RPC: {command.cmd}")
108+
logger.info("Executing command via RPC: %s", command.cmd)
109109

110110
job_result = self.client.run_command(command.cmd, timeout=self.timeout)
111111

112112
result = CommandResult(stdout=job_result.stdout, stderr=job_result.stderr, exit_code=job_result.returncode or 0)
113113
result.check_returncode()
114-
logger.info(f"RPC command completed with exit code: {result.exit_code}")
114+
logger.info("RPC command completed with exit code: %s", result.exit_code)
115115
return result
116116

117117
async def run_async(self, command: Command[Any]) -> CommandResult:
@@ -136,7 +136,7 @@ async def run_async(self, command: Command[Any]) -> CommandResult:
136136
print(f"Output: {result.stdout}")
137137
```
138138
"""
139-
logger.info(f"Executing command asynchronously via RPC: {command.cmd}")
139+
logger.info("Executing command asynchronously via RPC: %s", command.cmd)
140140
submission = self.client.submit_command(command.cmd)
141141
if submission.job_id is None:
142142
raise RuntimeError("Job submission failed: no job ID returned")
@@ -146,7 +146,7 @@ async def run_async(self, command: Command[Any]) -> CommandResult:
146146
result = CommandResult(stdout=job_result.stdout, stderr=job_result.stderr, exit_code=job_result.returncode or 0)
147147
result.check_returncode()
148148

149-
logger.info(f"RPC async command completed with exit code: {result.exit_code}")
149+
logger.info("RPC async command completed with exit code: %s", result.exit_code)
150150
return result
151151

152152
async def _wait_for_result_async(self, job_id: str):

tests/assets/experiment_import_mocks.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
@experiment(name="first_experiment")
55
def first_experiment(launcher: Launcher) -> None: # pragma: no cover - behavior not important
6-
launcher.logger.info(f"running first_experiment with mock_constant={mock_constant}")
6+
launcher.logger.info("running first_experiment with mock_constant=%s", mock_constant)
77

88

99
@experiment(name="second_experiment")

uv.lock

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)