PHPackages                             swissup/module-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. swissup/module-logger

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

swissup/module-logger
=====================

Swissup Logger module

2.0.0(4w ago)0617—2.5%1MITPHPCI passing

Since Apr 28Pushed 3w agoCompare

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

READMEChangelogDependencies (2)Versions (3)Used By (1)

module-logger
=============

[](#module-logger)

PSR-3 compliant PHP logging library with browser console and CLI output support. Designed for use in Magento 2 modules but has no Magento dependency.

Features
--------

[](#features)

- **BrowserConsoleLogger** — outputs logs to browser DevTools console via injected `` tags
    - Colored output by log level
    - Grouped logs with nesting
    - Global `window.plog` storage for in-browser debugging
    - Memory usage tracking per log entry
- **CliLogger** — outputs logs to terminal
    - ANSI colored output with auto-detection
    - Proper STDOUT/STDERR routing (errors → STDERR)
    - Grouped logs with indentation
    - Immediate or buffered output modes
- **LoggerSingleton** — keyed singleton, one logger instance per debug constant
    - Auto-selects CLI or Browser logger based on `PHP_SAPI`
    - Returns `NullLogger` when debug mode is off (zero overhead in production)

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

[](#installation)

```
composer require swissup/module-logger
```

Usage
-----

[](#usage)

### LoggerSingleton (recommended)

[](#loggersingleton-recommended)

Enable debug mode by defining a constant before Magento bootstrap:

```
// in pub/index.php or app/etc/env.php
define('MY_MODULE_DEBUG', true);
```

Then use anywhere in your module:

```
use Swissup\Logger\Logger\LoggerSingleton;

$logger = LoggerSingleton::getInstance('MY_MODULE_DEBUG', '[MyModule]');

$logger->info('Processing started');
$logger->debug('Item loaded', ['id' => 42]);
$logger->warning('Cache miss', ['key' => 'product_1']);
$logger->error('Failed to connect', ['host' => 'localhost']);
```

When `MY_MODULE_DEBUG` is not defined or not `true`, `getInstance()` returns `NullLogger` — no overhead.

### PSR-3 wrapper in your module

[](#psr-3-wrapper-in-your-module)

```
use Psr\Log\AbstractLogger;
use Swissup\Logger\Logger\LoggerSingleton;

class MyLogger extends AbstractLogger
{
    #[\ReturnTypeWillChange]
    public function log($level, $message, array $context = []): void
    {
        LoggerSingleton::getInstance('MY_MODULE_DEBUG', '[MyModule]')->log($level, $message, $context);
    }
}
```

Then bind it in `di.xml`:

```

```

### BrowserConsoleLogger

[](#browserconsolelogger)

Outputs logs as JavaScript to the browser console. Call `flush()` to get the `` block and inject it into your HTML response.

```
use Swissup\Logger\Logger\BrowserConsoleLogger;

$logger = new BrowserConsoleLogger(enableGlobalStorage: true, prefix: '[MyModule]');

$logger->group('Processing request');
$logger->info('Step 1 complete');
$logger->debug('Data loaded', ['rows' => 150]);
$logger->warning('Slow query', ['ms' => 320]);
$logger->groupEnd();

// Inject into response HTML
echo $logger->flush();
```

Browser output example:

```
▼ [MyModule] Processing request
  14:05:59.123 INFO  Step 1 complete
  14:05:59.145 DEBUG Data loaded {rows: 150}
  14:05:59.201 WARN  Slow query {ms: 320}

```

Access all logs in DevTools console:

```
window.plog         // keyed by timestamp
window.plog._entries // ordered array
```

### CliLogger

[](#clilogger)

Outputs logs to terminal. Immediate output by default.

```
use Swissup\Logger\Logger\CliLogger;

$logger = new CliLogger(prefix: '[MyModule]');

$logger->group('Processing');
$logger->debug('Step 1', ['size' => 1024]);
$logger->warning('Patch failed', ['nodeId' => 123]);
$logger->groupEnd();
```

Terminal output:

```
┌─ [MyModule] Processing
│ 14:05:59.123 DEBUG   Step 1 {"size":1024}
│ 14:05:59.145 WARNING Patch failed {"nodeId":123}
└─

```

Buffered mode (accumulate then flush):

```
$logger = new CliLogger(prefix: '[MyModule]', immediateOutput: false);
$logger->info('Step 1');
$logger->info('Step 2');
$output = $logger->flush(); // write all at once
```

Log Levels
----------

[](#log-levels)

All PSR-3 log levels are supported:

LevelCLI colorBrowser colorConsole method`emergency`Red bg`#8B0000``console.error``alert`Magenta bold`#DC143C``console.error``critical`Red bold`#FF0000``console.error``error`Red`#FF4500``console.error``warning`Yellow`#FFA500``console.warn``notice`Cyan`#4169E1``console.info``info`Green`#008000``console.info``debug`Gray`#808080``console.debug`Message Interpolation
---------------------

[](#message-interpolation)

Context values are interpolated into `{placeholder}` patterns in messages:

```
$logger->info('User {id} logged in from {ip}', ['id' => 42, 'ip' => '127.0.0.1']);
// → "User 42 logged in from 127.0.0.1"
```

Context Sanitization
--------------------

[](#context-sanitization)

Context arrays are automatically sanitized before JSON encoding:

- **Resources** → `"resource(stream)"`
- **Exceptions/Throwable** → `{_type, class, message, code, file, line}`
- **Objects with `__toString`** → string value
- **JsonSerializable objects** → JSON serialized
- **Other objects** → `"object(ClassName)"`
- **Nested arrays** → recursively sanitized

###  Health Score

41

—

FairBetter than 87% of packages

Maintenance94

Actively maintained with recent releases

Popularity19

Limited adoption so far

Community10

Small or concentrated contributor base

Maturity34

Early-stage or recently created project

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

Total

2

Last Release

28d ago

Major Versions

1.0.0 → 2.0.02026-05-12

### Community

Maintainers

![](https://www.gravatar.com/avatar/b5eb663f2c3faab23d84a3ea1e7cbb2ff3afb0e27c10eefd018e48455c997c07?d=identicon)[0m3r](/maintainers/0m3r)

---

Top Contributors

[![0m3r](https://avatars.githubusercontent.com/u/412612?v=4)](https://github.com/0m3r "0m3r (14 commits)")

###  Code Quality

TestsPHPUnit

### Embed Badge

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

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

###  Alternatives

[sentry/sentry

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

1.9k240.0M312](/packages/sentry-sentry)[matomo/matomo

Matomo is the leading Free/Libre open analytics platform

21.6k38.2k](/packages/matomo-matomo)[illuminate/log

The Illuminate Log package.

6425.0M597](/packages/illuminate-log)[tempest/framework

The PHP framework that gets out of your way.

2.2k31.1k11](/packages/tempest-framework)[api-platform/metadata

API Resource-oriented metadata attributes and factories

244.5M180](/packages/api-platform-metadata)[pagemachine/typo3-formlog

Form log for TYPO3

23233.9k7](/packages/pagemachine-typo3-formlog)

PHPackages © 2026

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