Skip to content

Commit 008ef8f

Browse files
Fixed bug with saving log file in API loop
1 parent 0e57a1a commit 008ef8f

File tree

1 file changed

+11
-10
lines changed

1 file changed

+11
-10
lines changed

kilosort/run_kilosort.py

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -342,17 +342,17 @@ def setup_logger(results_dir, verbose_console=False):
342342
ks_log = logging.getLogger('kilosort')
343343
ks_log.setLevel(logging.DEBUG)
344344

345+
# Add file handler at debug level, include timestamps and logging level
346+
# in text output.
347+
file = logging.FileHandler(results_dir / 'kilosort4.log', mode='w')
348+
file.setLevel(logging.DEBUG)
349+
text_format = '%(asctime)s %(name)-12s %(levelname)-8s %(message)s'
350+
file_formatter = logging.Formatter(text_format)
351+
file.setFormatter(file_formatter)
352+
345353
# Skip this if the handlers were already added, like when running multiple
346354
# times in a single session.
347355
if not ks_log.handlers:
348-
# Add file handler at debug level, include timestamps and logging level
349-
# in text output.
350-
file = logging.FileHandler(results_dir / 'kilosort4.log', mode='w')
351-
file.setLevel(logging.DEBUG)
352-
text_format = '%(asctime)s %(name)-12s %(levelname)-8s %(message)s'
353-
file_formatter = logging.Formatter(text_format)
354-
file.setFormatter(file_formatter)
355-
356356
# Add console handler at info level with shorter messages,
357357
# unless verbose is requested.
358358
console = logging.StreamHandler()
@@ -363,10 +363,11 @@ def setup_logger(results_dir, verbose_console=False):
363363
console.setLevel(logging.INFO)
364364
console_formatter = logging.Formatter('%(name)-12s: %(message)s')
365365
console.setFormatter(console_formatter)
366-
367-
ks_log.addHandler(file)
368366
ks_log.addHandler(console)
369367

368+
# Always add file handler since log file might change locations
369+
ks_log.addHandler(file)
370+
370371

371372
def close_logger():
372373
ks_log = logging.getLogger('kilosort')

0 commit comments

Comments
 (0)