# Path: kwiklib/utils/logger.py
# def register(logger):
#     name = logger.name
#     if name not in LOGGERS:
#         LOGGERS[name] = logger
# 
# def unregister(logger):
#     name = logger.name
#     if name in LOGGERS:
#         LOGGERS[name].close()
#         del LOGGERS[name]
# 
# class FileLogger(Logger):
#     def __init__(self, filename=None, **kwargs):
#         kwargs['handler'] = logging.FileHandler(filename)
#         super(FileLogger, self).__init__(**kwargs)
#         
#     def close(self):
#         self.handler.close()
#         self._logger.removeHandler(self.handler)
#         del self.handler
#         del self._logger
# 
# def debug(self, msg):
#     self._logger.debug(self.get_message(msg))
# 
# def info(self, msg):
#     self._logger.info(self.get_message(msg))
# 
# def warn(self, msg):
#     self._logger.warn(self.get_message(msg))


import os
import os.path
import re
import xml.etree.ElementTree as ET
import numpy as np
import pandas as pd
from loader import (Loader, default_group_info, reorder, renumber_clusters,
    default_cluster_info)
from tools import (load_text, normalize,
    load_binary, load_pickle, save_text, get_array,
    first_row, load_binary_memmap)
from selection import (select, select_pairs, get_spikes_in_clusters,
    get_some_spikes_in_clusters, get_some_spikes, get_indices)
from kwiklib.utils.logger import (register, unregister, FileLogger, 
    debug, info, warn)
from kwiklib.utils.colors import COLORS_COUNT, generate_colors
        self.read_group_info()
        self.read_masks()
        self.report_progress(4, 5)
        self.read_waveforms()
        self.report_progress(5, 5)
        # self.read_stats()
    
    def save(self, renumber=False):
        self.update_cluster_info()
        self.update_group_info()
        
        if renumber:
            self.renumber()
            clusters = get_array(self.clusters_renumbered)
            cluster_info = self.cluster_info_renumbered
        else:
            clusters = get_array(self.clusters)
            cluster_info = self.cluster_info
        
        # Save both ACLU and CLU files.
        save_clusters(self.filename_aclu, clusters)
        save_clusters(self.filename_clu, 
            convert_to_clu(clusters, cluster_info['group']))
        
        # Save CLUINFO and GROUPINFO files.
        save_cluster_info(self.filename_acluinfo, cluster_info)
        save_group_info(self.filename_groupinfo, self.group_info)
    
    def close(self):
        if hasattr(self, 'logfile'):

# Path: kwiklib/utils/logger.py
# def register(logger):
#     name = logger.name
#     if name not in LOGGERS:
#         LOGGERS[name] = logger
# 
# def unregister(logger):
#     name = logger.name
#     if name in LOGGERS:
#         LOGGERS[name].close()
#         del LOGGERS[name]
# 
# class FileLogger(Logger):
#     def __init__(self, filename=None, **kwargs):
#         kwargs['handler'] = logging.FileHandler(filename)
#         super(FileLogger, self).__init__(**kwargs)
#         
#     def close(self):
#         self.handler.close()
#         self._logger.removeHandler(self.handler)
#         del self.handler
#         del self._logger
# 
# def debug(self, msg):
#     self._logger.debug(self.get_message(msg))
# 
# def info(self, msg):
#     self._logger.info(self.get_message(msg))
# 
# def warn(self, msg):
#     self._logger.warn(self.get_message(msg))


# Path: kwiklib/dataio/klustersloader.py
import os
import os.path
import re
import xml.etree.ElementTree as ET
import numpy as np
import pandas as pd
from loader import (Loader, default_group_info, reorder, renumber_clusters,
    default_cluster_info)
from tools import (load_text, normalize,
    load_binary, load_pickle, save_text, get_array,
    first_row, load_binary_memmap)
from selection import (select, select_pairs, get_spikes_in_clusters,
    get_some_spikes_in_clusters, get_some_spikes, get_indices)
from kwiklib.utils.logger import (register, unregister, FileLogger, 
    debug, info, warn)
from kwiklib.utils.colors import COLORS_COUNT, generate_colors

        self.read_group_info()
        self.read_masks()
        self.report_progress(4, 5)
        self.read_waveforms()
        self.report_progress(5, 5)
        # self.read_stats()
    
    def save(self, renumber=False):
        self.update_cluster_info()
        self.update_group_info()
        
        if renumber:
            self.renumber()
            clusters = get_array(self.clusters_renumbered)
            cluster_info = self.cluster_info_renumbered
        else:
            clusters = get_array(self.clusters)
            cluster_info = self.cluster_info
        
        # Save both ACLU and CLU files.
        save_clusters(self.filename_aclu, clusters)
        save_clusters(self.filename_clu, 
            convert_to_clu(clusters, cluster_info['group']))
        
        # Save CLUINFO and GROUPINFO files.
        save_cluster_info(self.filename_acluinfo, cluster_info)
        save_group_info(self.filename_groupinfo, self.group_info)
    
    def close(self):
        if hasattr(self, 'logfile'):

            unregister(self.logfile)