From ae5f090cc41954a5fa60e1c94d936ef64742dead Mon Sep 17 00:00:00 2001 From: Andrew Mirsky Date: Mon, 22 Apr 2024 15:16:17 -0400 Subject: [PATCH] if using 'muse' within another package, use 'logger' so that messages can be redirected to appropriate output stream (#198) changing default logging stream to stdout to match current behavior of `print` statements --- muselsl/muse.py | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/muselsl/muse.py b/muselsl/muse.py index 9e69f37..b23c3eb 100644 --- a/muselsl/muse.py +++ b/muselsl/muse.py @@ -1,3 +1,6 @@ +import logging +import sys + import bitstring import pygatt import numpy as np @@ -8,6 +11,9 @@ from . import helper from .constants import * +logging.basicConfig(stream=sys.stdout, level=logging.DEBUG) +logger = logging.getLogger(__name__) + class Muse(): """Muse 2016 headband""" @@ -64,11 +70,11 @@ def connect(self, interface=None): """Connect to the device""" try: if self.backend == 'bluemuse': - print('Starting BlueMuse.') + logger.info('Starting BlueMuse.') subprocess.call('start bluemuse:', shell=True) self.last_timestamp = self.time_func() else: - print('Connecting to %s: %s...' % (self.name + logger.info('Connecting to %s: %s...' % (self.name if self.name else 'Muse', self.address)) if self.backend == 'gatt': @@ -145,7 +151,7 @@ def connect(self, interface=None): return True else: - print('Connection to', self.address, 'failed') + logger.error('Connection to', self.address, 'failed') return False def _write_cmd(self, cmd): @@ -260,7 +266,7 @@ def select_preset(self, preset=21): if preset[0] == 'p': preset = preset[1:] if str(preset) != '21': - print('Sending command for non-default preset: p' + preset) + logger.debug('Sending command for non-default preset: p' + preset) preset = bytes(preset, 'utf-8') self._write_cmd([0x04, 0x70, *preset, 0x0a]) @@ -368,7 +374,7 @@ def _handle_eeg(self, handle, data): if handle == 35: if tm != self.last_tm + 1: if (tm - self.last_tm) != -65535: # counter reset - print("missing sample %d : %d" % (tm, self.last_tm)) + logger.debug("missing sample %d : %d" % (tm, self.last_tm)) # correct sample index for timestamp estimation self.sample_index += 12 * (tm - self.last_tm + 1) @@ -564,7 +570,7 @@ def _handle_ppg(self, handle, data): # last data received if handle == 62: if tm != self.last_tm_ppg + 1: - print("missing sample %d : %d" % (tm, self.last_tm_ppg)) + logger.debug("missing sample %d : %d" % (tm, self.last_tm_ppg)) self.last_tm_ppg = tm # calculate index of time samples