Open zEdS15B3GCwq opened 1 year ago
As a workaround, it is possible to avoid invoking basicConfig
at all, e.g. the below code sets various handlers and formatting, and works:
import logging
from snirf import Snirf
fmt = logging.Formatter(
fmt="%(asctime)s,%(msecs)d %(levelname)-8s [%(filename)s:%(lineno)d] %(message)s",
datefmt="%Y-%m-%d:%H:%M:%S",
)
_filelogger = logging.FileHandler("test.log")
_filelogger.setLevel(logging.DEBUG)
_filelogger.setFormatter(fmt)
_streamlogger = logging.StreamHandler()
_streamlogger.setLevel(logging.WARNING)
_streamlogger.setFormatter(fmt)
log = logging.getLogger(__name__)
log.setLevel(logging.DEBUG)
log.addHandler(_filelogger)
log.addHandler(_streamlogger)
with Snirf("test.snirf", "w") as f:
f.nirs.appendGroup()
f.save()
log.debug("debug")
log.warning("warning")
Nevertheless, I think it's still better to fix the cause of the exception.
Hi, thanks for this--sorry to see I have misused the logging module. I am not actively maintaining this project and will take awhile to get to this fix. I can help you integrate the changes with the generative code if you make the necessary changes to the header.py
Thanks for the response. I'd love to contribute, but right now I'm too busy elsewhere, sorry. With the above workaround, my code works fine, and perhaps others who bump into the same issue can learn from it too. I hope you find the time to work on it one day.
It seems to be fixed in: https://github.com/BUNPC/pysnirf2/commit/74242b74caf203f9c5ec44fb64281c2f88acf7a6
Is there a chance to trigger new official release?
I will try and move through a release now/in the coming days @ptrhbt
Hopefully this is fixed in the new release but I will await confirmation
Hi,
Windows 11 Python 3.11.4 snirf 0.7.4
I'm learning to use the module to create snirf files from scratch. I've run into a problem, where my code also uses the
logging
module and setslogging.basicConfig
, and it results in aTypeError
exception being thrown onsave()
. Minimal example follows:Running this code results in:
No exception is thrown if the code only changes a property of the snirf root (e.g.
formatVersion
), but doesn't append anirs
group. Removing thelogging.basicConfig
line also removes the error.