Skip to content

Commit

Permalink
RF: make logging messages independent of active level - 1: hits alway…
Browse files Browse the repository at this point in the history
…s at DEBUG

With this change logging looks like

    2024-08-21 09:42:39,718 [    INFO] 2 out of 5 paths are not unique.
     2 paths 'compete' for the path 'sub-P53CS/sub-P53CS_ses-20171101_ecephys+image.nwb':
      /home/yoh/proj/dandi/dandisets/000004/sub-P53CS/sub-P53CS_ses-20171101_obj-108aqix_ecephys+image.nwb
      /home/yoh/proj/dandi/dandisets/000004/sub-P53CS/sub-P53CS_ses-20171101_obj-lj04dr_ecephys+image.nwb
     1 more case(s) are listed at DEBUG level.
    2024-08-21 09:42:39,718 [   DEBUG] Additional non-unique paths:
     3 paths 'compete' for the path 'sub-P54CS/sub-P54CS_ses-20180101_ecephys+image.nwb':
      /home/yoh/proj/dandi/dandisets/000004/sub-P54CS/sub-P54CS_ses-20180101_obj-1ru98u8_ecephys+image.nwb
      /home/yoh/proj/dandi/dandisets/000004/sub-P54CS/sub-P54CS_ses-20180101_obj-1ukzk61_ecephys+image.nwb
      /home/yoh/proj/dandi/dandisets/000004/sub-P54CS/sub-P54CS_ses-20180101_obj-1vx1a5w_ecephys+image.nwb
    2024-08-21 09:42:39,718 [    INFO] We will try adding _obj- based on crc32 of object_id
  • Loading branch information
yarikoptic committed Aug 21, 2024
1 parent c47269b commit e456ebb
Showing 1 changed file with 11 additions and 14 deletions.
25 changes: 11 additions & 14 deletions dandi/organize.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
from collections.abc import Sequence
from copy import deepcopy
from enum import Enum
import logging
import os
import os.path as op
from pathlib import Path, PurePosixPath
Expand Down Expand Up @@ -312,24 +311,22 @@ def _assign_obj_id(metadata, non_unique):
non_unique_paths = sorted(non_unique)

# provide more information to the user
def get_msg(path, indent=" "):
def get_msg(path):
in_paths = non_unique[path]
return (
f"{len(in_paths)} paths 'compete' for the path {path!r}:"
+ f"\n{indent}".join([""] + in_paths)
return f"{len(in_paths)} paths 'compete' for the path {path!r}:" + "\n ".join(
[""] + in_paths
)

msg += "\n " + get_msg(non_unique_paths[0])
if len(non_unique) > 1:
if not lgr.isEnabledFor(logging.DEBUG):
msg += (
" Rerun with logging at DEBUG level '-l debug' "
"to see {len(non_unique) - 1} more cases."
)
else:
for ex_path in non_unique_paths[1:]:
msg += "\n " + get_msg(ex_path)
lgr.info("%s\n We will try adding _obj- based on crc32 of object_id", msg)
msg += f"\n {len(non_unique) - 1} more case(s) are listed at DEBUG level."

Check warning on line 322 in dandi/organize.py

View check run for this annotation

Codecov / codecov/patch

dandi/organize.py#L322

Added line #L322 was not covered by tests
lgr.info("%s", msg)
if len(non_unique) > 1:
msg = "Additional non-unique paths:"
for ex_path in non_unique_paths[1:]:
msg += "\n " + get_msg(ex_path)
lgr.debug("%s", msg)

Check warning on line 328 in dandi/organize.py

View check run for this annotation

Codecov / codecov/patch

dandi/organize.py#L325-L328

Added lines #L325 - L328 were not covered by tests
lgr.info("We will try adding _obj- based on crc32 of object_id")
seen_obj_ids = {} # obj_id: object_id
seen_object_ids = {} # object_id: path
recent_nwb_msg = "NWB>=2.1.0 standard (supported by pynwb>=1.1.0)."
Expand Down

0 comments on commit e456ebb

Please sign in to comment.