mo-logs
raw JSON → 8.703.26061 verified Mon Apr 27 auth: no python
Structured logging and exception handling library for Python, part of the mo-* family. Current version 8.703.26061. Provides structured logging with sensible defaults and a simple API. Release cadence is frequent and automated.
pip install mo-logs Common errors
error ModuleNotFoundError: No module named 'mo-logs' ↓
cause Trying to import with hyphen instead of underscore.
fix
Use
from mo_logs import Log (with underscore). error AttributeError: module 'mo_logs' has no attribute 'Log' ↓
cause Using `import mo_logs` then `mo_logs.Log` but the package may have changed export patterns.
fix
Use
from mo_logs import Log. Warnings
breaking Import path changed: from `mo_logs` not `mo-logs`. Python package uses underscores, not hyphens. ↓
fix Use `from mo_logs import Log` instead of `from mo-logs import Log`.
gotcha Call `setup_logging()` before any logging to ensure configuration is applied. If omitted, logging defaults may not be set. ↓
fix Always call `setup_logging()` at application startup.
gotcha Do not use `import mo-logs` directly; the package is not designed to be imported as a module. Always import specific symbols like `Log`. ↓
fix Use `from mo_logs import Log`.
deprecated The `start` function in `mo_logs` is deprecated. Use `setup_logging()` instead. ↓
fix Replace `from mo_logs import start; start()` with `from mo_logs import setup_logging; setup_logging()`.
Imports
- Log
from mo_logs import Log - setup_logging
from mo_logs import setup_logging - Except
from mo_logs import Except
Quickstart
from mo_logs import Log, setup_logging
from mo_logs import constants
# Setup logging (call once at startup)
setup_logging()
# Basic logging
Log.note("This is a log message")
Log.note("Message with {field}", field="value")
# Warning
Log.warning("This is a warning")
# Error handling
from mo_logs import Except
try:
raise ValueError("something went wrong")
except ValueError as e:
error = Except.wrap(e)
Log.error("An error occurred: {error}", error=error)
# Set constants (like DEBUG flag)
constants.set({"DEBUG": True})