PHPackages                             initphp/logger - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Logging &amp; Monitoring](/categories/logging)
4. /
5. initphp/logger

ActiveLibrary[Logging &amp; Monitoring](/categories/logging)

initphp/logger
==============

PSR-3 compliant logger with File and PDO handlers, plus a multiplexer for sending each log record to several handlers at once.

2.0.0(1mo ago)217011MITPHPPHP &gt;=8.0CI passing

Since Mar 15Pushed 3w ago1 watchersCompare

[ Source](https://github.com/InitPHP/Logger)[ Packagist](https://packagist.org/packages/initphp/logger)[ RSS](/packages/initphp-logger/feed)WikiDiscussions main Synced today

READMEChangelog (3)Dependencies (5)Versions (7)Used By (1)

InitPHP Logger
==============

[](#initphp-logger)

A small, focused, PSR-3 compliant logger for PHP 8.0+. Ships with two built-in handlers and a tiny multiplexer that fans every log record out to several handlers at once.

[![Latest Stable Version](https://camo.githubusercontent.com/b63d28b17b13ac442a8011f3e3e43e9f16553a185c75e8d7dd3be4d2afefb84f/68747470733a2f2f706f7365722e707567782e6f72672f696e69747068702f6c6f676765722f76)](https://packagist.org/packages/initphp/logger)[![Total Downloads](https://camo.githubusercontent.com/7873671a42cb312baabddbb22afd6454e532f81739c8516aafe4075bd9c81d1f/68747470733a2f2f706f7365722e707567782e6f72672f696e69747068702f6c6f676765722f646f776e6c6f616473)](https://packagist.org/packages/initphp/logger)[![License](https://camo.githubusercontent.com/d3f6c797ae46f886f08c9d9933fee036c858636035b17e2d63c6b99bc2f730b2/68747470733a2f2f706f7365722e707567782e6f72672f696e69747068702f6c6f676765722f6c6963656e7365)](https://packagist.org/packages/initphp/logger)[![PHP Version Require](https://camo.githubusercontent.com/5eda3f73dd84d0167750fd3963e6044fb668f17c0e7ad65672cc145b6214d3ae/68747470733a2f2f706f7365722e707567782e6f72672f696e69747068702f6c6f676765722f726571756972652f706870)](https://packagist.org/packages/initphp/logger)

At a glance
-----------

[](#at-a-glance)

- **`FileLogger`** — appends each record as a single line to a file, with optional date-token placeholders in the path (`{year}/{month}/{day}/...`).
- **`PDOLogger`** — inserts each record as a row in a relational table, using prepared statements. Works with any PDO driver (MySQL, PostgreSQL, SQLite…).
- **`Logger`** — accepts any number of `Psr\Log\LoggerInterface` instances and forwards every call to all of them, in registration order.

Everything implements `Psr\Log\LoggerInterface` (PSR-3 v3), so you can drop the package into any framework or library that consumes that contract — or compose it with handlers from other PSR-3 packages.

Requirements
------------

[](#requirements)

RequirementVersionPHP`>= 8.0`[`psr/log`](https://packagist.org/packages/psr/log)`^3.0``ext-pdo`Required only for `PDOLogger`Installation
------------

[](#installation)

```
composer require initphp/logger
```

Quick start
-----------

[](#quick-start)

```
require __DIR__ . '/vendor/autoload.php';

use InitPHP\Logger\FileLogger;
use InitPHP\Logger\Logger;

$logger = new Logger(
    new FileLogger(['path' => __DIR__ . '/logs/app.log'])
);

$logger->info('Service booted in {ms}ms', ['ms' => 42]);
$logger->error('Payment {id} failed', ['id' => 9182]);
```

Produces, for example:

```
2026-05-24T14:08:22+03:00 [INFO] Service booted in 42ms
2026-05-24T14:08:22+03:00 [ERROR] Payment 9182 failed

```

Handlers
--------

[](#handlers)

### FileLogger

[](#filelogger)

```
use InitPHP\Logger\FileLogger;

$logger = new FileLogger([
    'path' => __DIR__ . '/logs/app-{year}-{month}-{day}.log',
]);
```

Path tokens (`{year}`, `{month}`, `{day}`, `{hour}`, `{minute}`, `{second}`) are resolved once, at construction time, against the process clock. The parent directory is created automatically (mode `0775`) if it does not already exist. Writes use `FILE_APPEND | LOCK_EX`, so concurrent processes do not interleave bytes within a single record.

Full reference: [`docs/02-file-logger.md`](docs/02-file-logger.md).

### PDOLogger

[](#pdologger)

```
use InitPHP\Logger\PDOLogger;

$pdo = new PDO('mysql:host=localhost;dbname=app;charset=utf8mb4', 'app', 'secret');
$pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);

$logger = new PDOLogger(['pdo' => $pdo, 'table' => 'logs']);

$logger->error('User {user} caused an error.', ['user' => 'muhammetsafak']);
// INSERT INTO logs (level, message, date) VALUES ('ERROR', 'User muhammetsafak caused an error.', '2026-05-24 14:08:22')
```

Reference DDL for MySQL:

```
CREATE TABLE `logs` (
    `id`      BIGINT UNSIGNED AUTO_INCREMENT PRIMARY KEY,
    `level`   ENUM('EMERGENCY','ALERT','CRITICAL','ERROR','WARNING','NOTICE','INFO','DEBUG') NOT NULL,
    `message` TEXT NOT NULL,
    `date`    DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
    KEY `idx_logs_level_date` (`level`, `date`)
) ENGINE = InnoDB CHARSET = utf8mb4 COLLATE utf8mb4_general_ci;
```

PostgreSQL and SQLite variants are documented in [`docs/03-pdo-logger.md`](docs/03-pdo-logger.md).

### Multi-handler logging

[](#multi-handler-logging)

```
use InitPHP\Logger\FileLogger;
use InitPHP\Logger\Logger;
use InitPHP\Logger\PDOLogger;

$logger = new Logger(
    new FileLogger(['path' => __DIR__ . '/logs/app.log']),
    new PDOLogger(['pdo' => $pdo, 'table' => 'logs'])
);

$logger->warning('cache miss for key {key}', ['key' => 'user:42']);
// Goes to BOTH the file and the database table.
```

`Logger` accepts any `Psr\Log\LoggerInterface`, including handlers from other PSR-3 packages — see [`docs/05-custom-handlers.md`](docs/05-custom-handlers.md).

PSR-3 surface
-------------

[](#psr-3-surface)

Every handler exposes the full PSR-3 API:

```
$logger->emergency(string|\Stringable $message, array $context = []): void;
$logger->alert    (string|\Stringable $message, array $context = []): void;
$logger->critical (string|\Stringable $message, array $context = []): void;
$logger->error    (string|\Stringable $message, array $context = []): void;
$logger->warning  (string|\Stringable $message, array $context = []): void;
$logger->notice   (string|\Stringable $message, array $context = []): void;
$logger->info     (string|\Stringable $message, array $context = []): void;
$logger->debug    (string|\Stringable $message, array $context = []): void;
$logger->log      ($level, string|\Stringable $message, array $context = []): void;
```

Context placeholders (`{name}`) are expanded with the matching key from `$context`. Booleans render as `true` / `false`, `null` renders as the empty string, `\Throwable` values render as `Class(code): message in file:line`, and anything implementing `__toString()` is cast to string. Arrays and non-stringable objects are skipped — see [`docs/06-psr3-context.md`](docs/06-psr3-context.md).

Unknown log levels throw `Psr\Log\InvalidArgumentException`, per PSR-3 §1.1.

Documentation
-------------

[](#documentation)

Topic-by-topic guides live in [`docs/`](docs/):

- [`01-getting-started.md`](docs/01-getting-started.md)
- [`02-file-logger.md`](docs/02-file-logger.md)
- [`03-pdo-logger.md`](docs/03-pdo-logger.md)
- [`04-multi-logger.md`](docs/04-multi-logger.md)
- [`05-custom-handlers.md`](docs/05-custom-handlers.md)
- [`06-psr3-context.md`](docs/06-psr3-context.md)
- [`07-recipes.md`](docs/07-recipes.md)
- [`08-testing-your-logging.md`](docs/08-testing-your-logging.md)

Testing the package itself
--------------------------

[](#testing-the-package-itself)

```
composer install
composer test         # PHPUnit
composer phpstan      # PHPStan (level max)
composer cs-check     # PHP-CS-Fixer dry-run
composer ci           # all of the above
```

Contributing
------------

[](#contributing)

Please read the org-wide [`CONTRIBUTING.md`](https://github.com/InitPHP/.github/blob/main/CONTRIBUTING.md)before opening a pull request. Bug reports and feature ideas go through [Issues](https://github.com/InitPHP/Logger/issues) and [Discussions](https://github.com/orgs/InitPHP/discussions).

Security
--------

[](#security)

If you discover a security vulnerability, please follow the instructions in the org-wide [`SECURITY.md`](https://github.com/InitPHP/.github/blob/main/SECURITY.md). Do **not** open a public issue.

License
-------

[](#license)

Released under the [MIT License](LICENSE). Copyright © InitPHP.

###  Health Score

47

—

FairBetter than 93% of packages

Maintenance94

Actively maintained with recent releases

Popularity14

Limited adoption so far

Community10

Small or concentrated contributor base

Maturity58

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~306 days

Recently: every ~383 days

Total

6

Last Release

40d ago

Major Versions

1.x-dev → 2.0.02026-05-24

PHP version history (2 changes)1.0PHP &gt;=5.6

2.0.0PHP &gt;=8.0

### Community

Maintainers

![](https://www.gravatar.com/avatar/4b6b34f3ac8938d8ee52ba3bd260680855dc5715c7b2929d9380de30d15a67dd?d=identicon)[muhammetsafak](/maintainers/muhammetsafak)

---

Top Contributors

[![muhammetsafak](https://avatars.githubusercontent.com/u/104234499?v=4)](https://github.com/muhammetsafak "muhammetsafak (4 commits)")

---

Tags

file-loggerinitphplogloggerpdo-loggerphpphp-libraryphp8psr-3psr-logpsr3logpsr-3loggingloggerPSR3file-loggerpdo-logger

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan

Code StylePHP CS Fixer

Type Coverage Yes

### Embed Badge

![Health badge](/badges/initphp-logger/health.svg)

```
[![Health](https://phpackages.com/badges/initphp-logger/health.svg)](https://phpackages.com/packages/initphp-logger)
```

###  Alternatives

[analog/analog

Fast, flexible, easy PSR-3-compatible PHP logging package with dozens of handlers.

3511.6M24](/packages/analog-analog)[inpsyde/wonolog

Monolog-based logging package for WordPress.

184637.3k7](/packages/inpsyde-wonolog)[apix/log

Minimalist, thin and fast PSR-3 compliant (multi-bucket) logger.

521.1M20](/packages/apix-log)[markrogoyski/simplelog-php

Powerful PSR-3 logging. So easy, it's simple.

2819.3k4](/packages/markrogoyski-simplelog-php)[atrapalo/monolog-elasticsearch

A Monolog handler and formatter that makes use of the elasticsearch/elasticsearch package

1123.0k](/packages/atrapalo-monolog-elasticsearch)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
