✅ Binding the popular Rust logging library spdlog-rs via FFI for Mojo usage.
✅ Redesigned API inspired by Python's loguru logging library for improved usability.
🐝 Binding spdlog-rs logging library for mojo 🔥
简体中文 | English
✅ Support logging to: console, file, stdout, stderr
✅ Support custom log format
✅ Support log level configuration
✅ Support colored logs
# First add channel sources, including spdlog-ffi package and spdlog package
channels = [
" https://conda.modular.com/max-nightly" ,
" https://repo.prefix.dev/better-ffi" , # contains spdlog-ffi package
" https://repo.prefix.dev/better-mojo" , # contains spdlog mojo package
" conda-forge" ,
]
# Add dependency packages
[dependencies ]
mojo = " >=1.0.0b2.dev2026052706,<2" # TODO X: fix version inconsistency issue!!!
# FFI dependency
libspdlog_ffi = " >=0.1.0,<0.2"
# Mojo package dependency
# spdlog = { git = "https://github.com/better-mojo/logger.git", branch = "main" }
spdlog = " >=0.1.2,<0.2"
from spdlog import get_logger
def main () raises -> None :
var logger = get_logger()
logger.info(" Hello, World!" )
logger.debug(" Processing item {} of {} " , " 5" , " 100" )
logger.warn(" Disk usage is at {} %" , " 85" )
# Run logging example
pixi run mojo -I . examples/logger.mojo
✅ Complete example examples/try-uuid
Includes complete package dependency import methods
# Install dependencies
pixi install
# Run
pixi run mojo src/main.mojo
✅ Build and debug spdlog-ffi package
# Run examples
task ffi:r
# Build spdlog-ffi package
task ffi:b
# Release spdlog-ffi package
task ffi:rel
# Run examples
task run:logger
Release and Publish to Prefix.dev
# Publish spdlog-ffi package to prefix.dev
task m:q:rs
# Publish spdlog package to prefix.dev
task m:q:mojo
✅ Compile and release Linux version, based on orbstack virtual machine
Note: each time you need to publish the ffi library for 3 OS versions to prefix.dev first, then publish the spdlog package. (dependency order)
# List available virtual machines
orbctl list
# Connect to linux-aarch64 architecture virtual machine, execute compile + publish
orbctl run -m u22dev
# Connect to linux-64 architecture virtual machine, execute compile + publish
orbctl run -m u22build