Centralized Logging with Grafana Loki and Promtail
When you run a dozen self-hosted applications, searching logs across each one individually is not sustainable. Loki centralizes everything.
Every application generates logs. Web servers log every request. Databases log slow queries. Applications log errors. When a problem occurs, the first step is checking logs. But checking logs one application at a time, across multiple servers, is slow and frustrating. Centralized logging solves this by pulling all logs into one searchable, indexed system.
Why Loki?
Grafana Loki is the logging platform built for modern infrastructure. Unlike the ELK stack (Elasticsearch, Logstash, Kibana) which is powerful but resource-intensive, Loki is lightweight and designed for small-to-medium deployments. It indexes only metadata (labels like application name, server, severity) and leaves the log content unindexed, which dramatically reduces storage requirements. A typical Loki deployment uses a fraction of the RAM and disk space of a comparable Elasticsearch setup.
How It Works
Promtail, a lightweight log collector, runs on each server and tails log files from your Docker containers and system services. It attaches labels (which application, which server, which environment) and ships logs to Loki. Loki stores them efficiently in object storage or local disk. Grafana, which you may already use for monitoring, provides the query interface.
With everything in one place, you can answer questions like: Show all error-level logs across all applications in the last 15 minutes. Show every request to the CRM from a specific IP address. Show database slow queries across all databases.
What to Log
- Web server access logs: Every HTTP request with status code and response time
- Application logs: Errors, warnings, and audit events from your self-hosted apps
- Database logs: Slow queries, connection failures, replication status
- System logs: Authentication failures, sudo usage, service start and stop events
- Docker logs: Container stdout and stderr from every running service
Getting Started
Loki and Promtail run in Docker alongside your existing stack. They add minimal overhead: maybe 200MB RAM for Loki and 50MB for Promtail. The Grafana instance you already use for monitoring becomes your log viewer. VPS1 includes Loki and Promtail in our standard monitoring stack for managed clients.
More articles
Building a Team Wiki for Your Business with Outline
Outline replaces Notion and Confluence with a self-hosted knowledge base that is fast, clean, and fully under your control.
Google Photos vs. Immich: Self-Hosted Photo and Video Management
Immich is the self-hosted Google Photos alternative that gives you AI-powered search, facial recognition, and automatic backup without sending your media to the cloud.
Database Backup Strategies That Actually Work
Most backup failures are discovered during a restore attempt. Here is how to design a database backup strategy you can actually rely on.