PHPackages                             mafin/simple-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. mafin/simple-logger

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

mafin/simple-logger
===================

A simple PSR-3 compliant logging utility for PHP.

v1.0.0(6mo ago)08MITPHPPHP ^8.4

Since Jul 5Pushed 6mo ago1 watchersCompare

[ Source](https://github.com/mafin/simple-logger)[ Packagist](https://packagist.org/packages/mafin/simple-logger)[ RSS](/packages/mafin-simple-logger/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (2)Dependencies (7)Versions (3)Used By (0)

Simple Logger
=============

[](#simple-logger)

[![PHP Version](https://camo.githubusercontent.com/504ead6a583c68d8d62d7bfceed24e569ca613d7a36bed380281b3455b5c7b31/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f7068702d253545382e342d626c7565)](https://www.php.net/)[![PSR-3](https://camo.githubusercontent.com/8d653e4daef6f0cb88e2c5321f93e94388ceaf32a362c3ac4d467b63d9593b12/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f5053522d2d332d636f6d706c69616e742d677265656e)](https://www.php-fig.org/psr/psr-3/)[![License](https://camo.githubusercontent.com/7013272bd27ece47364536a221edb554cd69683b68a46fc0ee96881174c4214c/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d626c75652e737667)](LICENSE)

A simple, lightweight, and extensible PSR-3 compliant logging library for PHP 8.4+, built with SOLID principles and Dependency Injection support.

Features
--------

[](#features)

- ✅ **PSR-3 Compliant** - Fully implements PSR-3 LoggerInterface
- 🏗️ **SOLID Architecture** - Clean separation of concerns with interfaces
- 💉 **Dependency Injection** - Easily extensible with custom writers and formatters
- 🔒 **Thread-Safe** - File locking for concurrent writes
- 🎯 **Context Interpolation** - Replace placeholders with context values
- 📦 **Zero Dependencies** - Only requires `psr/log`
- ✨ **Type-Safe** - Full PHP 8.3+ type declarations
- 🧪 **Well Tested** - 100% test coverage with PHPUnit
- 📊 **Static Analysis** - PHPStan level max compliant

Installation
------------

[](#installation)

Install via Composer:

```
composer require mafin/simple-logger
```

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

[](#requirements)

- PHP 8.4 or higher
- psr/log ^3.0

Quick Start
-----------

[](#quick-start)

### Basic Usage

[](#basic-usage)

```
use Mafin\SimpleLogger\Logger;
use Psr\Log\LogLevel;

// Create a logger that writes to a file
$logger = new Logger('app.log', LogLevel::DEBUG);

// Log messages at different levels
$logger->info('This is an info message.');
$logger->error('This is an error message.');
$logger->debug('Debug information');
```

### Context Interpolation

[](#context-interpolation)

```
$logger->info('User {username} logged in from {ip}', [
    'username' => 'john_doe',
    'ip' => '192.168.1.1',
]);
// Output: [2025-11-05 12:34:56] [info] User john_doe logged in from 192.168.1.1
```

### Dependency Injection

[](#dependency-injection)

```
use Mafin\SimpleLogger\Infrastructure\FileLogWriter;
use Mafin\SimpleLogger\Infrastructure\DefaultLogFormatter;
use Mafin\SimpleLogger\Logger;
use Psr\Log\LogLevel;

// Custom writer
$writer = new FileLogWriter('logs/app.log');

// Custom formatter (optional)
$formatter = new DefaultLogFormatter();

// Inject dependencies
$logger = new Logger($writer, LogLevel::INFO, $formatter);
```

### Custom Writer

[](#custom-writer)

Implement your own log writer (database, API, etc.):

```
use Mafin\SimpleLogger\Contract\LogWriterInterface;

class DatabaseLogWriter implements LogWriterInterface
{
    public function __construct(private PDO $pdo) {}

    public function write(string $message): void
    {
        $stmt = $this->pdo->prepare('INSERT INTO logs (message) VALUES (?)');
        $stmt->execute([$message]);
    }
}

$logger = new Logger(new DatabaseLogWriter($pdo), LogLevel::INFO);
```

### Custom Formatter

[](#custom-formatter)

```
use Mafin\SimpleLogger\Contract\LogFormatterInterface;

class JsonFormatter implements LogFormatterInterface
{
    public function format(string $level, string|\Stringable $message, array $context = []): string
    {
        return json_encode([
            'timestamp' => time(),
            'level' => $level,
            'message' => (string) $message,
            'context' => $context,
        ]) . PHP_EOL;
    }
}

$logger = new Logger('app.log', LogLevel::DEBUG, new JsonFormatter());
```

Supported Log Levels
--------------------

[](#supported-log-levels)

All PSR-3 log levels are supported:

- `emergency` - System is unusable
- `alert` - Action must be taken immediately
- `critical` - Critical conditions
- `error` - Error conditions
- `warning` - Warning conditions
- `notice` - Normal but significant condition
- `info` - Informational messages
- `debug` - Debug-level messages

Architecture
------------

[](#architecture)

The library follows SOLID principles with clean separation:

```
src/
├── Contract/              # Interfaces (abstraction layer)
│   ├── LogWriterInterface.php
│   └── LogFormatterInterface.php
├── Infrastructure/        # Concrete implementations
│   ├── FileLogWriter.php
│   └── DefaultLogFormatter.php
└── Logger.php            # Main logger orchestration

```

Development
-----------

[](#development)

### Running Tests

[](#running-tests)

```
composer test
```

### Code Style Check

[](#code-style-check)

```
composer ecs
```

### Static Analysis

[](#static-analysis)

```
composer phpstan
```

### All Checks

[](#all-checks)

```
composer check
```

Changelog
---------

[](#changelog)

Please see [CHANGELOG](CHANGELOG.md) for more information on what has changed recently.

License
-------

[](#license)

The MIT License (MIT). Please see [License File](LICENSE) for more information.

Credits
-------

[](#credits)

- [Petr Jenin](https://github.com/mafin)

Security
--------

[](#security)

If you discover any security related issues, please email  instead of using the issue tracker.

###  Health Score

37

—

LowBetter than 83% of packages

Maintenance68

Regular maintenance activity

Popularity4

Limited adoption so far

Community7

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 ~488 days

Total

2

Last Release

187d ago

Major Versions

0.0.1 → v1.0.02025-11-05

PHP version history (2 changes)0.0.1PHP ^8.3

v1.0.0PHP ^8.4

### Community

Maintainers

![](https://www.gravatar.com/avatar/3c7e92639af259cdeb9cdf3cdc91cdada35d72987999cc0976182736fc6943cf?d=identicon)[mafin](/maintainers/mafin)

---

Top Contributors

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

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan

Code StylePHP CS Fixer

Type Coverage Yes

### Embed Badge

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

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

###  Alternatives

[sentry/sentry

PHP SDK for Sentry (http://sentry.io)

1.9k227.1M273](/packages/sentry-sentry)[rollbar/rollbar

Monitors errors and exceptions and reports them to Rollbar

33723.7M82](/packages/rollbar-rollbar)[illuminate/log

The Illuminate Log package.

6224.3M518](/packages/illuminate-log)[open-telemetry/sdk

SDK for OpenTelemetry PHP.

2222.9M248](/packages/open-telemetry-sdk)[open-telemetry/api

API for OpenTelemetry PHP.

1833.0M214](/packages/open-telemetry-api)[pagemachine/typo3-formlog

Form log for TYPO3

23225.3k6](/packages/pagemachine-typo3-formlog)

PHPackages © 2026

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