Weave Code
Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Monolog Mysql Laravel Package

wazaari/monolog-mysql

Monolog handler that writes Laravel and PHP log records straight to MySQL. Ships with a ready-made schema, configurable table and connection, buffered bulk inserts for speed, and level filtering. Drops into Laravel's logging stack with minimal setup.

View on GitHub
Deep Wiki
Context7

Technical Evaluation

Architecture fit

  • Monolog is the logging abstraction underneath Laravel’s illuminate/log, so a Monolog handler is the correct integration seam. A custom channel using driver => monolog can add MySQL persistence without changing application logging calls.
  • The handler performs a synchronous PDO INSERT per log record. That is simple and transparent, but it couples the request path to MySQL availability, latency, and connection limits. MySQL is not a log-native store: no ingestion pipeline, compression, retention, or multi-service aggregation.
  • Good fit for low-to-moderate volume, SQL-queryable audit/security/application events, and teams already standardized on MySQL.
  • Poor fit for high-volume debug logging, multi-service log aggregation, or environments that already have ELK/Loki/CloudWatch. It should not become the primary observability sink.

Integration feasibility

  • Composer install; MIT license; requires PDO/JSON extensions. Small dependency footprint.
  • Requires a PDO instance and table/column configuration. Laravel does not bind PDO by default, so integration needs a service provider binding or a small handler factory. Laravel’s handler_with positional construction is awkward for a PDO-first constructor; a wrapper is cleaner.
  • No Laravel migrations are shipped. The team owns DDL: table creation, column types (TEXT/JSON, DATETIME(6)), utf8mb4, and indexes. Column mapping and JSON-encoded context/extra are the main customization points.
  • Happy-path spike: roughly half a day to one day. Production hardening: one to two weeks including schema, failure isolation, retention, and load testing.

Technical risk

  • Version compatibility is the first gate. The 2021 release predates Monolog 3, which replaced array records with LogRecord. If the constraint is Monolog 1/2 only, Laravel 10/11 adoption is blocked without a fork or patch.
  • Maintenance risk is material: last release November 2021, single maintainer, 139 stars, zero dependents, low opportunity score. Treat it as vendored utility code, not a strategic dependency. No security response process is evident.
  • Logging failures can propagate. A DB outage or timeout during write() can turn a log call into a 5xx or added latency unless wrapped with WhatFailureGroupHandler or an equivalent fail-open guard.
  • Long-running workers (Octane, Swoole, RoadRunner) can hold stale PDO connections; the handler has no evident reconnect/ping logic.
  • Unbounded table growth, index write overhead, JSON encoding failures on invalid UTF-8, max_allowed_packet limits, and PII exposure in context/extra are all foreseeable.

Key questions

  • Which Laravel and Monolog versions must be supported? Is Monolog 3 required?
  • Expected log volume (records/sec, bytes/day) and retention period?
  • Separate MySQL instance/connection, or shared with application data?
  • Is there an existing central log platform? If so, why MySQL?
  • Octane/Swoole in use? What reconnect behavior is required?
  • PII/compliance constraints for logged context and extra?
  • Who owns schema, retention, upgrades, and on-call?
  • Is the right decision adopt, fork, or build a ~100-line custom Laravel handler?

Integration Approach

Stack fit

  • Sweet spot: Laravel 8/9 with Monolog 2. Laravel 10/11 typically requires Monolog 3 and therefore a patch or alternative.
  • Use a dedicated logging database connection with least-privilege INSERT credentials. Resolve PDO lazily through a wrapper so reconnects and Octane worker recycling are handled outside the package.
  • Register a mysql channel in config/logging.php and attach it to the stack channel for dual-write during rollout.

Migration path

  • Phase 0: install, create the table, write and query a test log from artisan tinker.
  • Phase 1: parallel run. Add the MySQL channel alongside the existing daily/single channel; file logs remain authoritative.
  • Phase 2: migrate selected channels first—audit, security, payments—while leaving debug logging on files.
  • Phase 3: cut over after a soak period, then remove redundant file handlers for migrated channels.
  • Rollback is config-only: remove the channel from the stack and revert to file logging. Keep file logs during the soak window.

Compatibility

  • Pin monolog/monolog and Laravel versions explicitly; add composer audit and Dependabot.
  • If Monolog 3 is required, fork under the organization namespace, bump the constraint, adapt write() to accept LogRecord, add a PHP/CI matrix, and publish via private Packagist or Satis. Estimate one to three days.
  • Compare fork cost against a custom handler built on Laravel’s DB connection and queue. The custom path is often cheaper and enables async/batching and native reconnect behavior.

Sequencing

  1. Confirm versions, volume, retention, and build-vs-fork decision.
  2. Add versioned schema migration and DDL to the application repository.
  3. Build a wrapper handler: lazy PDO resolution, fail-open error handling, optional buffering or sampling.
  4. Add container binding, channel config, and environment variables.
  5. Dual-write in staging; load test at 2–5x expected peak volume.
  6. Add retention/partition job, dashboards, and alerts on write failures and table size.
  7. Roll out per environment with a runbook and on-call briefing.

Operational Impact

Maintenance

  • Low upstream activity means the adopting team effectively becomes the maintainer. Budget one to two days per quarter for PHP/Monolog upgrades and security review.
  • Zero dependents means little community pressure for fixes. Vendor or fork the code if long-term use is expected.
  • Schema changes must live in application migrations and pass code review; do not rely on manual DDL drift.

Support

  • Community-only support: 139 stars, no commercial backing, no visible security policy. An internal owner is mandatory.
  • Document handler behavior in the runbook: synchronous write, one INSERT per record, JSON encoding of context/extra, table and column mapping.
  • Monitor insert latency, write failure rate, table growth, replication lag, and connection errors.

Scaling

  • Scales linearly with log volume. At roughly 1,000 records/sec, MySQL becomes a bottleneck; at 10,000 records/sec, it is not viable without batching or async ingestion.
  • Mitigations: filter to INFO+ in production, sample debug events, use FingersCrossedHandler or BufferHandler, offload to a queue, partition by day, retain 7–30 days, and isolate the logging database on separate disk/instance.
  • Every secondary index slows inserts. Index only queried columns (channel, level, datetime) and rely on partition pruning for retention.
  • Size disk as bytes/record × records/day × retention, with at least 2x headroom.

Failure modes

  • DB down or slow: logging exceptions can fail requests or add timeout latency. Fail open with WhatFailureGroupHandler or a try/catch wrapper.
  • Stale PDO in long-running workers: “MySQL server has gone away.” Add reconnect/ping or lazy connection resolution.
  • Disk full, max_allowed_packet overflow, invalid UTF-8, or JSON encode failure: lost or truncated records. Alert on handler exceptions and track dropped-log counters.
  • Recursive logging: if the DB error handler logs to the same channel, guard against loops.
  • Timezone and charset drift: standardize on UTC and utf8mb4.
  • Retention deletes can cause lock contention; prefer partition drops over large DELETE ranges.
  • Security exposure: logs may contain PII/tokens. Redact before write, restrict the DB user to INSERT, encrypt at rest where required, and audit access.

Ramp-up

  • Happy path: under one day for a mid-level Laravel developer.
  • Production-ready: one to two weeks including schema, wrapper handler, retention, dashboards, and load testing.
  • Organizational ramp: a short runbook and on-call briefing, roughly one hour.
  • Recommendation: conditional adoption for low-volume, SQL-queryable audit logs on Laravel 8/9. Do not use as a primary or high-volume log sink. Fork or build a custom handler if Monolog 3, Octane, async writes, or batching are required.
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
se7enxweb/flysystem
lampwick/laravel
jeslage/statamic-emojis
micahdshackelford/rmap-laravel
draftsmaninc/draftsman
square-bit/laravel-volition
himito/laravel-mailman
htinlynn/genius-helper
maco-studios/hephaestus
elmogy/larafast
xeviant/laravel-paystack
gorilladash/laravel-website-sdk
martialbe/flysystem-oss
chondal/3312client
jeroen-g/flickr
opscale-co/nova-genbi
itsjustvita/laravel-retention
tequilarapido/trackit
gregsphotography/site-builder-filament
cabaoctavio/laravel-query-log