Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions cellpose/io.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,33 @@
io_logger = logging.getLogger(__name__)

def logger_setup(cp_path=".cellpose", logfile_name="run.log", stdout_file_replacement=None):
"""Set up logging to a file and stdout (or a file replacement).

Creates the log directory if it doesn't exist, removes any existing log
file, and configures the root logger to write INFO-level and above messages
to both a log file and stdout (or a replacement file).

Parameters
----------
cp_path : str, optional
Directory name under the user's home directory for log output.
Default is ".cellpose".
logfile_name : str, optional
Name of the log file created inside cp_path. Default is "run.log".
stdout_file_replacement : str or None, optional
If provided, log output is written to this file path instead of stdout.

Returns
-------
logger : logging.Logger
Configured logger for this module. Only INFO and above messages are
emitted by default. To enable debug output, call
``logger.setLevel(logging.DEBUG)`` on the returned logger.

Notes
-----
The log file is deleted and recreated on each call.
"""
cp_dir = pathlib.Path.home().joinpath(cp_path)
cp_dir.mkdir(exist_ok=True)
log_file = cp_dir.joinpath(logfile_name)
Expand Down
6 changes: 3 additions & 3 deletions cellpose/transforms.py
Original file line number Diff line number Diff line change
Expand Up @@ -612,7 +612,7 @@ def convert_image(x, channel_axis=None, z_axis=None, do_3D=False):
x_out[..., 0] = x
x = x_out
del x_out
transforms_logger.info(f'processing grayscale image with {x.shape[0], x.shape[1]} HW')
transforms_logger.debug(f'processing grayscale image with {x.shape[0], x.shape[1]} HW')
elif ndim == 3:
# assume 2d with channels
# find dim with smaller size between first and last dims
Expand All @@ -629,7 +629,7 @@ def convert_image(x, channel_axis=None, z_axis=None, do_3D=False):
x_out[..., :num_channels] = x[..., :num_channels]
x = x_out
del x_out
transforms_logger.info(f'processing image with {x.shape[0], x.shape[1]} HW, and {x.shape[2]} channels')
transforms_logger.debug(f'processing image with {x.shape[0], x.shape[1]} HW, and {x.shape[2]} channels')
elif ndim == 4:
# assume batch of 2d with channels

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