Download the PHP package larsgmortensen/litelog without Composer
On this page you can find all versions of the php package larsgmortensen/litelog. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download larsgmortensen/litelog
More information about larsgmortensen/litelog
Files in larsgmortensen/litelog
Package litelog
Short Description Ultra-fast, lightweight JSON logger for PHP with atomic append and safe log rotation.
License GPL-3.0-or-later
Homepage https://github.com/LarsGMortensen/LiteLog
Informations about the package litelog
LiteLog β A Lightweight & High-Performance JSON Logger for PHP
LiteLog is a fast, minimal, efficient, single-file JSON logger focused on robustness and runtime performance.
It provides atomic appends, safe log rotation, and strict error handling with zero dependencies.
Designed for high-traffic PHP applications that require reliable logging without external bloat (PHP 8.0+).
π Features that make LiteLog stand out
- Blazing-fast writes β Appends JSON lines with atomic
LOCK_EXsafety. - Safe concurrency β Multiple processes can write concurrently without losing lines.
- Log rotation β Automatically rotates logs when file size exceeds threshold.
- Retention policy β Configurable pruning of old rotated logs.
- JSON by default β Structured, machine-readable logs with
timestamp,category,message, and optionalcontext. - Error-hardening β Fails fast if directory is missing, not writable, or JSON encoding fails.
- Minimal overhead β One file, static API, no runtime dependencies.
- Secure by default β Filenames are sanitized to prevent path traversal attacks.
- Production-ready β Verified by functional, benchmark, and concurrency tests.
π¦ Installation
Via Composer (recommended):
`
Or manually include the class file (e.g. src/LiteLog/LiteLog.php) with Composerβs autoloader or require_once:
Tip: Always place your log directory outside webroot, or protect it with
.htaccess.
π Quick Start
Example log output (JSON line)
π§° API
Parameters
- \$dir: Log directory (must exist unless
$createIfMissing=true). - \$file: Filename (e.g.
app.json). Must be a clean name, no path traversal. - \$category: Category string (
error,info, etc.). - \$message: String, array, or object. Arrays/objects are JSON-encoded automatically.
- \$context: Optional associative array with extra metadata (e.g., request id, ip).
- \$bytes: Maximum file size before rotation. Default: 10 MB.
- \$count: Number of rotated logs to keep.
nulldisables pruning.
π Usage Notes
- All log entries are one JSON line per entry β easy to parse with tools like
jqor ELK. - Rotation creates files like
app_1695030618123.json. - If retention is set, only the latest N rotated logs are kept; older are pruned.
- Fail-fast philosophy: if directory is missing or not writable, LiteLog throws immediately.
π§ͺ Tests
LiteLog is verified by three test suites:
-
Sanity tests (
test_litelog_new.php) Validates JSON encoding, rotation, retention, and path sanitization. -
Benchmarks (
bench_litelog.php,bench_litelog_web.php) Measures performance vs. old implementation. Results (shared hosting, 100k lines):- OLD: \~1643 ops/s
- NEW: \~1476 ops/s (β10% overhead for safe locking)
- Concurrency test (
concurrency_run.php) Spawns multiple parallel PHP processes writing to the same log file. β 400 000 lines written without loss or duplication under rotation.
π‘ Why LiteLog?
LiteLog exists for developers who want reliable structured logging without dragging in heavy frameworks.
β¨ Fast β 1.5β2k ops/s even on modest hardware.
β¨ Safe β Atomic writes, no lost lines under concurrency.
β¨ Structured β JSON lines are machine-readable.
β¨ Lightweight β One file, static API, no dependencies.
β¨ Robust β Strict error handling, sanitization, rotation + retention built-in.
π¦ Packagist
LiteLog on Packagist: π https://packagist.org/packages/larsgmortensen/litelog
π License
LiteLog is released under the GNU General Public License v3.0. See LICENSE for details.
π€ Contributing
Contributions are welcome! Fork, submit issues, or open a pull request.
βοΈ Author
Developed by Lars Grove Mortensen Β© 2025. Feel free to reach out or contribute!
LiteLog β the lightweight JSON logger you can trust π
π If you find this library useful, give it a star on GitHub! π
All versions of litelog with dependencies
ext-json Version *