Enable Logging¶
dataversefs uses loguru for structured logging. Logging is disabled by default — importing the package produces no output. This guide shows how to turn it on and control what you see.
Basic usage¶
import sys
from loguru import logger
# Remove the default handler to avoid duplicate output in Jupyter/IPython
logger.remove()
# Add a handler and enable the dataversefs namespace
logger.add(sys.stdout, level="INFO", filter="dataversefs", colorize=False)
logger.enable("dataversefs")
After this, every routing table fetch is logged to stdout. To go back to silence:
logger.disable("dataversefs")
Log levels¶
| Level | What is logged |
|---|---|
INFO |
Routing table fetch start and finish (with elapsed time); number of files registered |
DEBUG |
Every HEAD request to resolve a 303 redirect and every GET Range request for a file chunk |
INFO gives you a timing overview with minimal output. DEBUG produces one line per network request — useful for diagnosing slow reads or unexpected fetches, but verbose during Zarr computation.
Jupyter note¶
In Jupyter, loguru's default handler writes to stderr, which means calling logger.add() without first calling logger.remove() creates a second handler and you see duplicate lines. Always call logger.remove() first.
Use colorize=False to avoid ANSI escape codes appearing as raw characters in notebook output cells.
# Correct pattern for Jupyter
logger.remove()
logger.add(sys.stdout, level="INFO", filter="dataversefs", colorize=False)
logger.enable("dataversefs")
Selective DEBUG output¶
DEBUG logs one line per HEAD and GET request. For a Zarr compute that touches
thousands of chunks, this floods the notebook. A clean pattern is to enable DEBUG
only for a specific block and then drop back to INFO:
# Temporarily enable DEBUG for one operation
logger.remove()
logger.add(sys.stdout, level="DEBUG", filter="dataversefs", colorize=False)
logger.enable("dataversefs")
ds.isel(time=0).load() # watch every chunk request
logger.remove()
logger.add(sys.stdout, level="INFO", filter="dataversefs", colorize=False)