Integrations API
All integrations are available as submodules of logly.integrations. Most use importlib.util.find_spec to check for optional dependencies - no installation required if you don't use them.
from logly.integrations import fastapi, django, flaskFastAPI
LoglyMiddleware
from logly.integrations.fastapi import LoglyMiddleware
app = FastAPI()
app.add_middleware(LoglyMiddleware, level="INFO")Parameters:
| Parameter | Type | Default | Description |
|---|---|---|---|
app | FastAPI | FastAPI application | |
level | str | "INFO" | Minimum log level |
format | str | None | None | Custom format string |
backtrace | bool | False | Include backtrace on exceptions |
diagnose | bool | False | Include variable values on exceptions |
Django
LoglyHandler
# settings.py
LOGGING = {
"handlers": {
"logly": {
"()": "logly.integrations.django.LoglyHandler",
"level": "INFO",
},
},
"root": {
"handlers": ["logly"],
"level": "INFO",
},
}Parameters:
| Parameter | Type | Default | Description |
|---|---|---|---|
level | str | int | "INFO" | Minimum log level |
format | str | None | None | Custom format string |
LoglyMiddleware
MIDDLEWARE = [
"logly.integrations.django.LoglyMiddleware",
# ... other middleware
]Parameters:
| Parameter | Type | Default | Description |
|---|---|---|---|
get_response | Callable | None | None | Django response callable |
Flask
LoglyHandler
from flask import Flask
from logly.integrations.flask import LoglyHandler
app = Flask(__name__)
handler = LoglyHandler()
handler.init_app(app)Methods:
init_app(app, **kwargs)
Initialize the handler with a Flask app.
| Parameter | Type | Default | Description |
|---|---|---|---|
app | Flask | Flask application | |
level | str | "INFO" | Minimum log level |
format | str | None | None | Custom format string |
Starlette
LoglyMiddleware
from starlette.applications import Starlette
from logly.integrations.starlette import LoglyMiddleware
app = Starlette()
app.add_middleware(LoglyMiddleware, level="INFO")Parameters:
| Parameter | Type | Default | Description |
|---|---|---|---|
app | Starlette | Starlette application | |
level | str | "INFO" | Minimum log level |
format | str | None | None | Custom format string |
Stdlib Logging
InterceptHandler
Bridge stdlib logging to Logly.
import logging
from logly.integrations.stdlib import InterceptHandler
logging.basicConfig(handlers=[InterceptHandler()], level=logging.INFO)Parameters:
| Parameter | Type | Default | Description |
|---|---|---|---|
level | int | logging.NOTSET | Minimum log level |
Structlog
logly_processor
import structlog
structlog.configure(
processors=[
logly.integrations.structlog.logly_processor(
logger_name="mylogger",
wrapper_class=structlog.BoundLogger,
),
],
)Parameters:
| Parameter | Type | Default | Description |
|---|---|---|---|
logger_name | str | None | None | Logger name key |
wrapper_class | type | None | None | Structlog wrapper class |
level | str | "INFO" | Minimum log level |
LoglyRenderer
structlog.configure(
processors=[
logly.integrations.structlog.LoglyRenderer(level="INFO"),
],
)Parameters:
| Parameter | Type | Default | Description |
|---|---|---|---|
level | str | "INFO" | Minimum log level |
format | str | None | None | Custom format string |
Rich Console
LoglyRichSink
from logly import logger
from logly.integrations.rich import LoglyRichSink
logger.add(LoglyRichSink(), level="INFO")Parameters:
| Parameter | Type | Default | Description |
|---|---|---|---|
file | IO | None | None | Output file (default: stderr) |
RichHandler
from logly.integrations.rich import RichHandler
handler = RichHandler(level="INFO", show_path=False)Parameters:
| Parameter | Type | Default | Description |
|---|---|---|---|
level | int | logging.NOTSET | Minimum log level |
show_path | bool | True | Show file path |
show_line_no | bool | False | Show line number |
show_time | bool | True | Show timestamp |
rich_tracebacks | bool | True | Use Rich tracebacks |
Gunicorn
LoglyWorker
# gunicorn.conf.py
from logly.integrations.gunicorn import LoglyWorker
worker_class = LoglyWorkersetup_gunicorn_logging
# gunicorn.conf.py
from logly.integrations.gunicorn import setup_gunicorn_logging
setup_gunicorn_logging(level="INFO")Parameters:
| Parameter | Type | Default | Description |
|---|---|---|---|
level | str | "INFO" | Minimum log level |
format | str | None | None | Custom format string |
Uvicorn
setup_uvicorn_logging
# uvicorn config
from logly.integrations.uvicorn import setup_uvicorn_logging
setup_uvicorn_logging(level="INFO")Parameters:
| Parameter | Type | Default | Description |
|---|---|---|---|
level | str | "INFO" | Minimum log level |
format | str | None | None | Custom format string |
get_log_config
from logly.integrations.uvicorn import get_log_config
config = get_log_config(level="INFO")
# Use with uvicorn: uvicorn.run(app, log_config=config)Parameters:
| Parameter | Type | Default | Description |
|---|---|---|---|
level | str | "INFO" | Minimum log level |
format | str | None | None | Custom format string |
Returns: dict - Uvicorn-compatible log config
Celery
setup_celery_logging
from logly.integrations.celery import setup_celery_logging
setup_celery_logging(level="INFO")Parameters:
| Parameter | Type | Default | Description |
|---|---|---|---|
level | str | "INFO" | Minimum log level |
format | str | None | None | Custom format string |
patch_task_logger
from logly.integrations.celery import patch_task_logger
@app.task
def my_task():
patch_task_logger(app.task_logger, level="INFO")Parameters:
| Parameter | Type | Default | Description |
|---|---|---|---|
task_logger | Logger | Celery task logger | |
level | str | "INFO" | Minimum log level |
SQLAlchemy
setup_sqlalchemy_logging
from logly.integrations.sqlalchemy import setup_sqlalchemy_logging
setup_sqlalchemy_logging(level="WARNING", echo=False)Parameters:
| Parameter | Type | Default | Description |
|---|---|---|---|
level | str | "WARNING" | Minimum log level |
echo | bool | False | Echo SQL statements |
patch_engine
from logly.integrations.sqlalchemy import patch_engine
engine = create_engine("sqlite:///db.sqlite3")
patch_engine(engine, level="INFO")Parameters:
| Parameter | Type | Default | Description |
|---|---|---|---|
engine | Engine | SQLAlchemy engine | |
level | str | "INFO" | Minimum log level |
OpenTelemetry
OTelLogSink
from logly import logger
from logly.integrations.opentelemetry import OTelLogSink
logger.add(
OTelLogSink(
service_name="myapp",
endpoint="http://localhost:4318",
protocol="http",
)
)Parameters:
| Parameter | Type | Default | Description |
|---|---|---|---|
service_name | str | "logly" | Service name |
endpoint | str | "http://localhost:4318" | OTLP endpoint |
protocol | str | "http" | Protocol: "http" or "grpc" |
headers | dict | None | None | Request headers |
Prometheus
PrometheusLogSink
from logly import logger
from logly.integrations.prometheus import PrometheusLogSink
logger.add(PrometheusLogSink(namespace="logly"))Parameters:
| Parameter | Type | Default | Description |
|---|---|---|---|
namespace | str | "logly" | Prometheus namespace |
Subsystem | str | None | None | Prometheus subsystem |
Elasticsearch
ElasticsearchSink
from logly import logger
from logly.integrations.elasticsearch import ElasticsearchSink
logger.add(
ElasticsearchSink(
endpoint="http://localhost:9200",
index="logs",
)
)Parameters:
| Parameter | Type | Default | Description |
|---|---|---|---|
endpoint | str | Elasticsearch endpoint | |
index | str | "logly" | Index name |
timeout | int | 30 | Request timeout (seconds) |
username | str | None | None | Basic auth username |
password | str | None | None | Basic auth password |
Sentry
SentrySink
from logly import logger
from logly.integrations.sentry import SentrySink
logger.add(
SentrySink(
dsn="https://examplePublicKey@o0.ingest.sentry.io/0",
environment="production",
release="1.0.0",
level="WARNING",
)
)Parameters:
| Parameter | Type | Default | Description |
|---|---|---|---|
dsn | str | Sentry DSN | |
environment | str | None | None | Environment name |
release | str | None | None | Release version |
level | str | "WARNING" | Minimum log level |
Redis
RedisHandler
from logly import logger
from logly.integrations.redis import RedisHandler
logger.add(
RedisHandler(
url="redis://localhost:6379",
key="logs",
mode="list",
)
)Parameters:
| Parameter | Type | Default | Description |
|---|---|---|---|
url | str | Redis connection URL | |
key | str | "logly:logs" | Redis key |
mode | str | "list" | Storage mode: "list" or "stream" |
timeout | int | 5 | Connection timeout (seconds) |
max_stream_len | int | 10000 | Max stream length |
Kafka
KafkaHandler
from logly import logger
from logly.integrations.kafka import KafkaHandler
logger.add(
KafkaHandler(
bootstrap_servers="localhost:9092",
topic="logs",
)
)Parameters:
| Parameter | Type | Default | Description |
|---|---|---|---|
bootstrap_servers | str | Kafka broker addresses | |
topic | str | "logly" | Kafka topic |
client_id | str | None | None | Client ID |
acks | str | int | "all" | Acknowledgment mode |
timeout | int | 10 | Request timeout (seconds) |
MongoDB
MongoHandler
from logly import logger
from logly.integrations.mongodb import MongoHandler
logger.add(
MongoHandler(
uri="mongodb://localhost:27017",
database="logs",
collection="app_logs",
)
)Parameters:
| Parameter | Type | Default | Description |
|---|---|---|---|
uri | str | MongoDB connection URI | |
database | str | Database name | |
collection | str | "logs" | Collection name |
timeout | int | 5 | Connection timeout (seconds) |
PostgreSQL
PostgresHandler
from logly import logger
from logly.integrations.postgresql import PostgresHandler
logger.add(
PostgresHandler(
dsn="postgresql://user:pass@localhost:5432/logs",
table="app_logs",
)
)Parameters:
| Parameter | Type | Default | Description |
|---|---|---|---|
dsn | str | PostgreSQL connection string | |
table | str | "logs" | Table name |
create_table | bool | True | Auto-create table |
Discord
DiscordHandler
from logly import logger
from logly.integrations.discord import DiscordHandler
logger.add(
DiscordHandler(
webhook_url="https://discord.com/api/webhooks/...",
username="Logly Bot",
)
)Parameters:
| Parameter | Type | Default | Description |
|---|---|---|---|
webhook_url | str | Discord webhook URL | |
timeout | int | 10 | Request timeout (seconds) |
username | str | None | None | Override username |
avatar_url | str | None | None | Override avatar URL |
Slack
SlackHandler
from logly import logger
from logly.integrations.slack import SlackHandler
logger.add(
SlackHandler(
webhook_url="https://hooks.slack.com/services/...",
channel="#logs",
)
)Parameters:
| Parameter | Type | Default | Description |
|---|---|---|---|
webhook_url | str | Slack webhook URL | |
channel | str | None | None | Override channel |
username | str | "Logly" | Bot username |
icon_emoji | str | ":robot_face:" | Bot icon emoji |
timeout | int | 10 | Request timeout (seconds) |
Email
EmailHandler
from logly import logger
from logly.integrations.email import EmailHandler
logger.add(
EmailHandler(
smtp_host="smtp.gmail.com",
smtp_port=587,
from_addr="alerts@myapp.com",
to_addrs=["admin@myapp.com"],
username="alerts@myapp.com",
password="app-password",
use_tls=True,
)
)Parameters:
| Parameter | Type | Default | Description |
|---|---|---|---|
smtp_host | str | SMTP server host | |
smtp_port | int | SMTP server port | |
from_addr | str | Sender email address | |
to_addrs | list[str] | Recipient email addresses | |
username | str | None | None | SMTP username |
password | str | None | None | SMTP password |
use_tls | bool | True | Use STARTTLS |
use_ssl | bool | False | Use SSL/TLS |
timeout | int | 30 | Connection timeout (seconds) |
subject_prefix | str | "" | Prefix for email subject |
HTTP
HttpHandler
from logly import logger
from logly.integrations.http import HttpHandler
logger.add(
HttpHandler(
url="https://api.example.com/logs",
method="POST",
headers={"Authorization": "Bearer token"},
)
)Parameters:
| Parameter | Type | Default | Description |
|---|---|---|---|
url | str | HTTP endpoint URL | |
method | str | "POST" | HTTP method |
headers | dict | None | None | Request headers |
timeout | int | 10 | Request timeout (seconds) |
format | str | None | None | Custom format string |
Loki
LokiSink
from logly import logger
from logly.integrations.loki import LokiSink
logger.add(
LokiSink(
endpoint="http://localhost:3100",
labels={"app": "myapp", "env": "production"},
)
)Parameters:
| Parameter | Type | Default | Description |
|---|---|---|---|
endpoint | str | Loki endpoint URL | |
labels | dict | {} | Default labels |
timeout | int | 10 | Request timeout (seconds) |
username | str | None | None | Basic auth username |
password | str | None | None | Basic auth password |
Propagate
PropagateHandler
import logging
from logly.integrations.propagate import PropagateHandler
logging.getLogger("myapp").addHandler(PropagateHandler())Parameters:
| Parameter | Type | Default | Description |
|---|---|---|---|
name | str | "logly" | Logger name |
level | int | logging.NOTSET | Minimum log level |
Telemetry
TelemetrySink
from logly import logger
from logly.integrations.telemetry import TelemetrySink
def send_to_collector(record):
# Send to your telemetry backend
pass
logger.add(TelemetrySink(emit=send_to_collector))Parameters:
| Parameter | Type | Default | Description |
|---|---|---|---|
emit | Callable | Emission function | |
service_name | str | "logly" | Service name |
environment | str | None | None | Environment name |
HttpJsonSink
from logly import logger
from logly.integrations.telemetry import HttpJsonSink
logger.add(
HttpJsonSink(
endpoint="https://api.example.com/telemetry",
headers={"Authorization": "Bearer token"},
)
)Parameters:
| Parameter | Type | Default | Description |
|---|---|---|---|
endpoint | str | HTTP endpoint URL | |
headers | dict | None | None | Request headers |
timeout | int | 10 | Request timeout (seconds) |
APScheduler
APSchedulerHandler
from logly.integrations.apscheduler import APSchedulerHandler
scheduler = APScheduler()
scheduler.add_job(my_job, "interval", seconds=60)
scheduler.add_listener(APSchedulerHandler(), EVENT_JOB_EXECUTED)setup_apscheduler_logging
from logly.integrations.apscheduler import setup_apscheduler_logging
setup_apscheduler_logging(level="INFO")Parameters:
| Parameter | Type | Default | Description |
|---|---|---|---|
level | str | "INFO" | Minimum log level |
RQ
RQHandler
from logly.integrations.rq import RQHandler
# Attach to RQ workersetup_rq_logging
from logly.integrations.rq import setup_rq_logging
setup_rq_logging(level="INFO")Parameters:
| Parameter | Type | Default | Description |
|---|---|---|---|
level | str | "INFO" | Minimum log level |
Click
click_echo
from logly.integrations.click import click_echo
click_echo("Processing...", nl=True, err=True)Parameters:
| Parameter | Type | Default | Description |
|---|---|---|---|
message | str | Message to display | |
file | IO | None | None | Output stream |
nl | bool | True | Add newline |
err | bool | False | Output to stderr |
color | bool | None | None | Enable color |
Typer
typer_echo
from logly.integrations.typer import typer_echo
typer_echo("Processing...", nl=True, err=True)Parameters:
| Parameter | Type | Default | Description |
|---|---|---|---|
message | str | Message to display | |
file | IO | None | None | Output stream |
nl | bool | True | Add newline |
err | bool | False | Output to stderr |
color | bool | None | None | Enable color |
RabbitMQ
RabbitMQHandler
from logly import logger
from logly.integrations.rabbitmq import RabbitMQHandler
logger.add(
RabbitMQHandler(
url="amqp://guest:guest@localhost:5672",
queue="logs",
)
)Parameters:
| Parameter | Type | Default | Description |
|---|---|---|---|
url | str | RabbitMQ connection URL | |
queue | str | "logly" | Queue name |
exchange | str | None | None | Exchange name |
routing_key | str | None | None | Routing key |
durable | bool | True | Durable queue |
timeout | int | 10 | Connection timeout (seconds) |
Pydantic
PydanticLogHandler
import logging
from logly.integrations.pydantic import PydanticLogHandler
handler = PydanticLogHandler()
handler.setLevel(logging.INFO)Routes Python logging records through Logly for Pydantic-based applications. No extra dependencies.
LoglyFormatter
import logging
from logly.integrations.pydantic import LoglyFormatter
handler = logging.StreamHandler()
handler.setFormatter(LoglyFormatter())| Parameter | Type | Default | Description |
|---|---|---|---|
logly_logger | Logger | None | None | Logly logger instance (uses global logger) |
tqdm
TqdmSink
from logly import logger
from logly.integrations.tqdm import TqdmSink
from tqdm import tqdm
logger.remove()
logger.add(TqdmSink(), colorize=True)
for i in tqdm(range(100)):
if i % 20 == 0:
logger.info("Processing item {}", i)| Parameter | Type | Default | Description |
|---|---|---|---|
tqdm_instance | Any | None | Optional tqdm class or instance |
Datadog
DatadogSink
from logly import logger
from logly.integrations.datadog import DatadogSink
logger.add(
DatadogSink(
api_key="your-api-key",
service="myapp",
environment="production",
)
)| Parameter | Type | Default | Description |
|---|---|---|---|
api_key | str | Datadog API key | |
host | str | None | None | Host name |
source | str | None | "python" | Log source |
service | str | None | None | Service name |
tags | list[str] | None | None | Tags list |
site | str | "datadoghq.com" | Datadog site |
timeout | float | 5.0 | Request timeout (seconds) |
New Relic
NewRelicSink
from logly import logger
from logly.integrations.newrelic import NewRelicSink
logger.add(
NewRelicSink(
license_key="your-license-key",
app_name="myapp",
)
)| Parameter | Type | Default | Description |
|---|---|---|---|
license_key | str | None | None | New Relic license key |
app_name | str | None | None | Application name |
Seq
SeqSink
from logly import logger
from logly.integrations.seq import SeqSink
logger.add(
SeqSink(
server_url="http://localhost:5341",
api_key="your-api-key",
)
)| Parameter | Type | Default | Description |
|---|---|---|---|
server_url | str | Seq server URL | |
api_key | str | None | None | API key |
event_template | dict[str, Any] | None | None | Additional fields for every event |
timeout | float | 5.0 | Request timeout (seconds) |
AWS CloudWatch
CloudWatchSink
from logly import logger
from logly.integrations.aws_cloudwatch import CloudWatchSink
logger.add(
CloudWatchSink(
log_group="/myapp/logs",
log_stream="production",
region="us-east-1",
)
)| Parameter | Type | Default | Description |
|---|---|---|---|
log_group | str | CloudWatch log group name | |
log_stream | str | CloudWatch log stream name | |
region | str | None | None | AWS region |
aws_access_key_id | str | None | None | AWS access key |
aws_secret_access_key | str | None | None | AWS secret key |
batch_size | int | 10000 | Events per batch |
flush_interval | float | 5.0 | Flush interval (seconds) |
create_group | bool | True | Auto-create log group |
create_stream | bool | True | Auto-create log stream |
Google Cloud Logging
GoogleCloudLoggingSink
from logly import logger
from logly.integrations.google_cloud_logging import GoogleCloudLoggingSink
logger.add(
GoogleCloudLoggingSink(
project_id="my-project",
log_name="myapp",
)
)| Parameter | Type | Default | Description |
|---|---|---|---|
project_id | str | GCP project ID | |
log_name | str | "logly" | Log name |
resource | Any | None | Monitored resource |
credentials | Any | None | GCP credentials |
Azure Monitor
AzureMonitorSink
from logly import logger
from logly.integrations.azure_monitor import AzureMonitorSink
logger.add(
AzureMonitorSink(
connection_string="InstrumentationKey=...",
)
)| Parameter | Type | Default | Description |
|---|---|---|---|
connection_string | str | None | None | Application Insights connection string |
instrumentation_key | str | None | None | Instrumentation key (legacy) |
Logstash
LogstashSink
from logly import logger
from logly.integrations.logstash import LogstashSink
logger.add(
LogstashSink(
host="localhost",
port=5959,
protocol="tcp",
)
)| Parameter | Type | Default | Description |
|---|---|---|---|
host | str | "localhost" | Logstash host |
port | int | 5959 | Logstash port |
protocol | str | "tcp" | Protocol: "tcp" or "udp" |
message_type | str | "logstash" | Event type |
tags | list[str] | None | None | Event tags |
key_prefix | str | "" | Key prefix for fields |
timeout | float | 5.0 | Connection timeout (seconds) |
Graylog
GraylogSink
from logly import logger
from logly.integrations.graylog import GraylogSink
logger.add(
GraylogSink(
host="localhost",
port=12201,
protocol="udp",
)
)| Parameter | Type | Default | Description |
|---|---|---|---|
host | str | "localhost" | Graylog host |
port | int | 12201 | Graylog port |
protocol | str | "udp" | Protocol: "tcp" or "udp" |
graylog_version | str | "1.1" | GELF version: "1.0" or "1.1" |
chunk_size | int | 8192 | UDP chunk size |
facility | str | None | None | Facility name |
hostname | str | None | None | Override hostname |
timeout | float | 5.0 | Connection timeout (seconds) |
