Skip to content

Loguru

Point Loguru at Logfire and your existing Loguru output shows up in Logfire as structured logs (individual timestamped records of something that happened), next to the traces (the full journey of one request through your app) from the rest of your code, with no change to how you write log calls.

What you’ll capture

  • Each Loguru log message
  • Its severity level (info, warning, error, and so on)
  • Its timestamp
  • Any structured fields you attach to the record

Before you start

You’ll need a Logfire project. Open Add data in your project (top navigation) and follow the setup for your language: it signs your machine in with logfire auth (a browser sign-in, no token to copy) and, for production or other languages, creates a write token (the credential your app uses to send data). New to Logfire? Start with Getting Started.

Installation

Install logfire:

Terminal
pip install logfire

This works with your existing loguru package: nothing extra to install. If you don’t have it yet, run pip install loguru in your terminal.

Usage

Call logfire.configure() to connect to your project, then add logfire.loguru_handler() as a Loguru sink so every record Loguru emits is also sent to Logfire.

main.py
from loguru import logger

import logfire

logfire.configure()

logger.configure(handlers=[logfire.loguru_handler()])
logger.info('Hello, {name}!', name='World')

Verify it worked

Run your program, then open the Live view in the Logfire web app. Within a few seconds you’ll see your message as a record.

Advanced

Scrubbing

Troubleshooting

Not seeing your logs in Logfire? Check that logfire.configure() ran first, your write token is set, and the Logfire handler is attached to Loguru via logger.configure(handlers=[...]).

Reference