diff --git a/unisens/entry.py b/unisens/entry.py index 715e1a4..f9991fc 100644 --- a/unisens/entry.py +++ b/unisens/entry.py @@ -20,6 +20,8 @@ from xml.etree.ElementTree import Element from copy import deepcopy +logger = logging.getLogger("unisens") + def get_module(name): try: @@ -215,7 +217,7 @@ def _set_channels(self, ch_names: List[str], n_data: int): # this means new channel names are indicated and will overwrite. assert len(ch_names) == n_data, f'len {ch_names}!={n_data}' if hasattr(self, 'channel'): - logging.warning('Channels present will be overwritten') + logger.warning('Channels present will be overwritten') self.remove_entry('channel') for name in ch_names: channel = MiscEntry('channel', key='name', value=name) @@ -226,7 +228,7 @@ def _set_channels(self, ch_names: List[str], n_data: int): 'Please provide a list of channel names with set_data().', category=DeprecationWarning, stacklevel=2) # we create new generic names for the channels - logging.info('No channel names indicated, will use generic names') + logger.info('No channel names indicated, will use generic names') for i in range(n_data): channel = MiscEntry('channel', key='name', value=f'ch_{i}') self.add_entry(channel) @@ -373,7 +375,7 @@ def remove_attr(self, name: str): del self.attrib[name] del self.__dict__[name] else: - logging.error('{} not in attrib'.format(name)) + logger.error('{} not in attrib'.format(name)) self._autosave() return self @@ -438,12 +440,12 @@ def __init__(self, id, attrib=None, parent='.', **kwargs): valid_filename(self.id) self._filename = os.path.join(self._folder, self.id) if not os.access(self._filename, os.F_OK): - logging.error('File {} does not exist'.format(self.id)) + logger.error('File {} does not exist'.format(self.id)) elif id: # writing entry valid_filename(id) if os.path.splitext(str(id))[-1] == '': - logging.warning('id should be a filename with extension ie. .bin') + logger.warning('id should be a filename with extension ie. .bin') self._filename = os.path.join(self._folder, id) self.set_attrib('id', id) # ensure subdirectories exist to write data @@ -623,7 +625,7 @@ def __init__(self, id=None, attrib=None, parent='.', assert decimalSeparator and separator, 'Must supply separators' if not self.id.endswith('csv'): - logging.warning(f'id "{id}" does not end in .csv') + logger.warning(f'id "{id}" does not end in .csv') csvFileFormat = MiscEntry('csvFileFormat', parent=self) csvFileFormat.set_attrib('decimalSeparator', decimalSeparator) @@ -652,8 +654,8 @@ def set_data(self, data: list, **kwargs): sep = self.csvFileFormat.separator dec = self.csvFileFormat.decimalSeparator - if len(data) == 0 or len(data[0]) < 2: logging.warning('Should supply at least two columns: ' \ - 'time and data') + if len(data) == 0 or len(data[0]) < 2: + logger.warning('Should supply at least two columns: time and data') write_csv(self._filename, data, sep=sep, decimal_sep=dec) diff --git a/unisens/main.py b/unisens/main.py index 340f31b..92dc09d 100644 --- a/unisens/main.py +++ b/unisens/main.py @@ -30,6 +30,8 @@ from .utils import AttrDict, strip, validkey, lowercase, make_key, indent from .utils import str2num +logger = logging.getLogger("unisens") + class Unisens(Entry): """ @@ -78,12 +80,12 @@ def __init__(self, folder: str, makenew=False, autosave=False, readonly=False, self._convert_nums = convert_nums if os.path.isfile(self._file) and not makenew: - logging.debug('loading unisens.xml from {}'.format(self._file)) + logger.debug('loading unisens.xml from {}'.format(self._file)) with warnings.catch_warnings(): warnings.simplefilter("ignore") self.read_unisens() else: - logging.debug('New unisens.xml will be created at {}'.format(self._file)) + logger.debug('New unisens.xml will be created at {}'.format(self._file)) if not timestampStart: now = datetime.datetime.now() timestampStart = now.strftime('%Y-%m-%dT%H:%M:%S') @@ -188,7 +190,7 @@ def unpack_element(self, element: (Element, ET)) -> Entry: entry = MiscEntry(name=name, attrib=attrib, parent=self._folder) else: if not 'Entry' in element.tag: - logging.warning('Unknown entry type: {}'.format(entryType)) + logger.warning('Unknown entry type: {}'.format(entryType)) name = element.tag entry = MiscEntry(name=name, attrib=attrib, parent=self._folder)