Backend: Error Monitoring
Go
Java
JS
Python
Ruby
Backend: Logging
Go
JS
Python
Ruby
Java
Hosting Providers
Backend: Tracing
Go
Node.js
Python
Native OpenTelemetry
Fullstack Frameworks
Overview
Self Host & Local Dev
Menu
Logging in Python with Loguru
Learn how to set up highlight.io with logs from Python Loguru.
1
Set up your frontend highlight.io integration.
First, make sure you've followed the frontend getting started guide.
2
Install the highlight-io python package.
Download the package from pypi and save it to your requirements. If you use a zip or s3 file upload to publish your function, you will want to make sure highlight-io
is part of the build.
poetry add highlight-io
# or with pip
pip install highlight-io
3
Initialize the Highlight SDK.
Setup the SDK with instrument_logging
disabled, while passing the highlight logging handler to loguru. instrument_logging=False
must be passed to make sure the loguru handler does not collide with built-in logging
instrumentation.
import highlight_io
H = highlight_io.H("<YOUR_PROJECT_ID>", instrument_logging=False)
4
Use loguru!
Logs are reported automatically from loguru logging methods. Visit the highlight logs portal and check that backend logs are coming in.
import highlight_io
from loguru import logger
H = highlight_io.H(
"<YOUR_PROJECT_ID>",
instrument_logging=False,
service_name="my-app",
service_version="git-sha",
environment="production",
)
logger.add(
H.logging_handler,
format="{message}",
level="INFO",
backtrace=True,
serialize=True,
)
def main():
logger.debug("That's it, beautiful and simple logging!", nice="one")
context_logger = logger.bind(ip="192.168.0.1", user="someone")
context_logger.info("Contextualize your logger easily")
5
Verify your backend logs are being recorded.
Visit the highlight logs portal and check that backend logs are coming in.