Skip to content

Commit 6dc4e75

Browse files
authored
Merge pull request #1412 from MouseLand/debug_logging
Set transforms logging to debug level and add logger setup documentation
2 parents 4fbdc7c + f931675 commit 6dc4e75

File tree

2 files changed

+30
-3
lines changed

2 files changed

+30
-3
lines changed

cellpose/io.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,33 @@
4747
io_logger = logging.getLogger(__name__)
4848

4949
def logger_setup(cp_path=".cellpose", logfile_name="run.log", stdout_file_replacement=None):
50+
"""Set up logging to a file and stdout (or a file replacement).
51+
52+
Creates the log directory if it doesn't exist, removes any existing log
53+
file, and configures the root logger to write INFO-level and above messages
54+
to both a log file and stdout (or a replacement file).
55+
56+
Parameters
57+
----------
58+
cp_path : str, optional
59+
Directory name under the user's home directory for log output.
60+
Default is ".cellpose".
61+
logfile_name : str, optional
62+
Name of the log file created inside cp_path. Default is "run.log".
63+
stdout_file_replacement : str or None, optional
64+
If provided, log output is written to this file path instead of stdout.
65+
66+
Returns
67+
-------
68+
logger : logging.Logger
69+
Configured logger for this module. Only INFO and above messages are
70+
emitted by default. To enable debug output, call
71+
``logger.setLevel(logging.DEBUG)`` on the returned logger.
72+
73+
Notes
74+
-----
75+
The log file is deleted and recreated on each call.
76+
"""
5077
cp_dir = pathlib.Path.home().joinpath(cp_path)
5178
cp_dir.mkdir(exist_ok=True)
5279
log_file = cp_dir.joinpath(logfile_name)

cellpose/transforms.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -612,7 +612,7 @@ def convert_image(x, channel_axis=None, z_axis=None, do_3D=False):
612612
x_out[..., 0] = x
613613
x = x_out
614614
del x_out
615-
transforms_logger.info(f'processing grayscale image with {x.shape[0], x.shape[1]} HW')
615+
transforms_logger.debug(f'processing grayscale image with {x.shape[0], x.shape[1]} HW')
616616
elif ndim == 3:
617617
# assume 2d with channels
618618
# find dim with smaller size between first and last dims
@@ -629,7 +629,7 @@ def convert_image(x, channel_axis=None, z_axis=None, do_3D=False):
629629
x_out[..., :num_channels] = x[..., :num_channels]
630630
x = x_out
631631
del x_out
632-
transforms_logger.info(f'processing image with {x.shape[0], x.shape[1]} HW, and {x.shape[2]} channels')
632+
transforms_logger.debug(f'processing image with {x.shape[0], x.shape[1]} HW, and {x.shape[2]} channels')
633633
elif ndim == 4:
634634
# assume batch of 2d with channels
635635

@@ -642,7 +642,7 @@ def convert_image(x, channel_axis=None, z_axis=None, do_3D=False):
642642
x_out[..., :num_channels] = x[..., :num_channels]
643643
x = x_out
644644
del x_out
645-
transforms_logger.info(f'processing image batch with {x.shape[0]} images, {x.shape[1], x.shape[2]} HW, and {x.shape[3]} channels')
645+
transforms_logger.debug(f'processing image batch with {x.shape[0]} images, {x.shape[1], x.shape[2]} HW, and {x.shape[3]} channels')
646646
else:
647647
# something is wrong: yell
648648
expected_shapes = "2D (H, W), 3D (H, W, C), or 4D (Z, H, W, C)"

0 commit comments

Comments
 (0)