danielme85/laravel-log-to-db
Laravel Log to DB adds a Monolog handler that writes application logs to a database table instead of files. Configure levels, channels, and a custom model, then query or browse logs with Eloquent for easier searching and monitoring.
users, tenants, and orders. That unlocks product features file logs can't support: per-account "recent activity" views, customer-facing audit history, admin support timelines, and "what exactly happened to this customer's request?" tooling — without a second event pipeline.storage/logs.Strong fit when:
Look elsewhere when:
daily channel, or Ray solve that with less surface area.stack/whatfailuregroup fallback to a file channel, and consider a separate connection or database.For executives: Today, when a customer reports a problem, an engineer has to shell into a server and grep text files, or we pay a third-party observability vendor for every gigabyte we ship them. This package lets our application write structured log and error events straight into the database we already run — no new vendor, no new infrastructure, no license fee. That buys two things. First, support can answer "what happened to this account?" in seconds from an admin screen instead of a 30-minute engineering escalation. Second, we get an auditable, retained history we control, which is directly useful for compliance and enterprise/on-prem deals that forbid sending data to outside services. The integration cost is small — configuration plus a database migration, roughly one to two engineering days including a spike. The honest risk is that this is a small open-source project with a thin maintainer base, so we should not make it load-bearing: I'd recommend we wrap it behind our own logging channel, keep a file-based fallback if the database write fails, and cap the exposure to error and audit-level events rather than all traffic. Ask: approve a one-sprint spike with a load test at our real log volume, and a decision review before we remove any existing logging path. Success looks like tier-1 support resolving customer issues without engineering, and a flat observability bill at 3× current traffic.
For engineering: This is a Monolog handler registered as a Laravel log channel — you keep writing Log::channel('db')->info(...) and framework exceptions flow through unchanged. Events persist via the query builder/Eloquent to MySQL, Postgres, or MongoDB. You control the schema, indexes, and retention pruning, and you can join to domain tables, which is the whole point. Guardrails to design in from day one: register it inside a stack with a file fallback so a database failure never swallows a log line; point it at a dedicated connection or separate database so log volume can't pressure primary transactions; index on timestamp plus the tenant/user keys you'll actually query; and define a prune/partition strategy before the table is large. Confirm the supported Laravel/PHP matrix against our target upgrade path, and check test coverage and issue activity before we depend on it — at 133 stars this is a thin dependency, so keep the call sites behind our own thin wrapper so a fork or replacement is a one-file change. Deliverable for the spike: p99 write latency at 10× our current event rate, index and storage growth projection for 90 days, and a redaction review of what our current logs actually contain.
How can I help you explore Laravel packages today?