Python
The loginformant-logging package is a handler for Python's built-in
logging module. It works with Flask, Django, FastAPI, or any Python 3.7+ script.
No third-party dependencies required — just the standard library.
1 Install
bash
pip install loginformant-logging
2 Configure your logger
python — logging_setup.py
import logging
import os
from loginformant import LogInformantHandler
# Create the handler
handler = LogInformantHandler(
api_url="https://app.loginformant.com",
api_key=os.environ["LOGINFORMANT_API_KEY"],
)
# Attach to the root logger (captures all modules)
logging.basicConfig(level=logging.INFO, handlers=[
logging.StreamHandler(), # also print to console
handler,
])
logger = logging.getLogger(__name__)
3 Log in your code
python
import logging
logger = logging.getLogger(__name__)
def place_order(order_id: int):
logger.info("Order %s placed", order_id)
try:
# your logic
pass
except Exception as e:
logger.error("Failed to place order %s", order_id, exc_info=True)
Django integration
Add the handler to Django's LOGGING dict in settings.py:
python — settings.py
import os
LOGGING = {
"version": 1,
"disable_existing_loggers": False,
"handlers": {
"console": {
"class": "logging.StreamHandler",
},
"loginformant": {
"class": "loginformant.LogInformantHandler",
"api_url": "https://app.loginformant.com",
"api_key": os.environ.get("LOGINFORMANT_API_KEY", ""),
"level": "WARNING",
},
},
"root": {
"handlers": ["console", "loginformant"],
"level": "INFO",
},
}
Flask integration
python — app.py
import logging
import os
from flask import Flask
from loginformant import LogInformantHandler
app = Flask(__name__)
# Attach handler to Flask's logger
handler = LogInformantHandler(
api_url="https://app.loginformant.com",
api_key=os.environ["LOGINFORMANT_API_KEY"],
)
app.logger.addHandler(handler)
app.logger.setLevel(logging.INFO)
Configuration options
| Parameter | Default | Description |
|---|---|---|
api_url | required | Your LogInformant instance URL |
api_key | required | Application API key |
batch_size | 50 | Max logs per HTTP request |
flush_interval | 2.0 | Flush interval in seconds |
level | WARNING | Minimum level (standard logging levels) |
Log level mapping
| Python | LogInformant |
|---|---|
| DEBUG | Debug |
| INFO | Information |
| WARNING | Warning |
| ERROR | Error |
| CRITICAL | Fatal |