Script icon
Docker icon

Logging configuration in a Python script using Loguru

Run a Python script with Loguru in Kestra, map log levels to Kestra logs, and control verbosity at runtime with a configurable input parameter.

Categories
Core

Configure clean, structured logging in a Python script using Loguru and run it inside Kestra so every message surfaces in the Kestra execution logs at the right severity. This blueprint solves a common problem for data engineers and Python developers: making script output observable, level-aware, and reproducible inside an orchestrator instead of buried in stdout. It generates a configurable batch of fake log lines so you can see exactly how Loguru levels map to Kestra log levels.

How it works

  1. The flow exposes one input, nr_logs (type INT, default 100), which controls how many log messages are produced at runtime.
  2. The reproducer task of type io.kestra.plugin.scripts.python.Script runs the Python code defined in its script property.
  3. The task uses a Docker taskRunner (io.kestra.plugin.scripts.runner.docker.Docker) and declares its dependencies (loguru and faker), so the packages are installed in an isolated container at runtime.
  4. Inside the script, Loguru is configured with logger.remove() and two sinks: sys.stdout at level INFO and sys.stderr at level WARNING.
  5. The script emits a logger.debug line (filtered out by the INFO threshold), logger.warning markers around the loop, and one logger.info line per generated Faker sentence.

What you get

  • A working example of Loguru sink and level configuration in Python.
  • logger.info mapped to INFO logs and logger.warning mapped to WARN logs inside Kestra.
  • Proof that logger.debug is suppressed when the level is set to INFO.
  • Runtime control of log volume through the nr_logs input.
  • A reproducible, containerized run with no local Python setup.

Who it's for

  • Python developers adopting Loguru for cleaner logging.
  • Data engineers who want script logs visible in their orchestrator.
  • Teams standardizing logging conventions across pipelines.

Why orchestrate this with Kestra

Kestra turns an ad hoc script into a governed, observable workflow. Log levels are captured and rendered natively in the UI, runs are reproducible thanks to declarative YAML and Docker-isolated dependencies, and you gain retries, event and schedule triggers, and full execution lineage. A bare Python script has no scheduler, no run history, and no centralized log view: Kestra fills exactly that gap.

Prerequisites

  • A running Kestra instance.
  • A Docker-enabled environment for the task runner.

Secrets

This flow uses no secrets. It runs entirely from public PyPI packages (loguru, faker) installed at runtime.

Quick start

  1. Add the flow to your Kestra instance.
  2. Trigger an execution, optionally overriding nr_logs.
  3. Open the execution and inspect the Logs tab to see INFO and WARN levels.
  4. Confirm the logger.debug line does not appear.

How to extend

  • Lower the stdout sink to DEBUG to surface debug messages.
  • Add Loguru file sinks or JSON serialization for structured logs.
  • Add a schedule or event trigger to run the script automatically.
  • Replace the Faker loop with your real application logic.

Links

Share this Blueprint
See How

New to Kestra?

Use blueprints to kickstart your first workflows.