diff --git a/cellpose/io.py b/cellpose/io.py index 5d081bb2..18833827 100644 --- a/cellpose/io.py +++ b/cellpose/io.py @@ -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) diff --git a/cellpose/transforms.py b/cellpose/transforms.py index 0de7bcb5..cc957b0e 100644 --- a/cellpose/transforms.py +++ b/cellpose/transforms.py @@ -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 @@ -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 @@ -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)"