diff --git a/src/spikeinterface/sorters/external/kilosort4.py b/src/spikeinterface/sorters/external/kilosort4.py index 68a0be4317..6070961ad4 100644 --- a/src/spikeinterface/sorters/external/kilosort4.py +++ b/src/spikeinterface/sorters/external/kilosort4.py @@ -163,6 +163,7 @@ def _run_from_folder(cls, sorter_output_folder, params, verbose): cluster_spikes, save_sorting, get_run_parameters, + setup_logger, ) from kilosort.io import load_probe, RecordingExtractorAsArray, BinaryFiltered, save_preprocessing from kilosort.parameters import DEFAULT_SETTINGS @@ -170,11 +171,7 @@ def _run_from_folder(cls, sorter_output_folder, params, verbose): import time import torch import numpy as np - - if verbose: - import logging - - logging.basicConfig(level=logging.INFO) + import logging if version.parse(cls.get_sorter_version()) < version.parse("4.0.16"): raise RuntimeError( @@ -183,6 +180,37 @@ def _run_from_folder(cls, sorter_output_folder, params, verbose): "Please upgrade Kilosort version." ) + # setup kilosort's console and file log handlers + setup_logger_takes_verbose_console = version.parse(cls.get_sorter_version()) > version.parse("4.0.18") + logger_is_named = version.parse(cls.get_sorter_version()) > version.parse("4.0.20") + + if setup_logger_takes_verbose_console: + # v4.0.19 and higher + setup_logger(sorter_output_folder, verbose_console=False) + else: + # v4.0.16, v4.0.17, v4.0.18 + setup_logger(sorter_output_folder) + + # if verbose is False, set the stream handler's log + # level to logging.WARNING to preserve original + # behavior prior to addition of setup_logger() above + if not verbose: + if logger_is_named: + # v4.0.21 and above + logger = logging.getLogger("kilosort") + else: + # v4.0.16, v4.0.17, v4.0.18, v4.0.19, v4.0.20 + logger = logging.getLogger("") + + # find the stream handler + stream_handler = None + for handler in logger.handlers: + if type(handler) == logging.StreamHandler: + stream_handler = handler + break + + stream_handler.setLevel(logging.WARNING) + sorter_output_folder = sorter_output_folder.absolute() probe_filename = sorter_output_folder / "chanMap.json"