Download the PHP package swissup/module-logger without Composer
On this page you can find all versions of the php package swissup/module-logger. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Informations about the package 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
- BrowserConsoleLogger — outputs logs to browser DevTools console via injected
<script>tags- Colored output by log level
- Grouped logs with nesting
- Global
window.plogstorage 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
NullLoggerwhen debug mode is off (zero overhead in production)
- Auto-selects CLI or Browser logger based on
Installation
Usage
LoggerSingleton (recommended)
Enable debug mode by defining a constant before Magento bootstrap:
Then use anywhere in your module:
When MY_MODULE_DEBUG is not defined or not true, getInstance() returns NullLogger — no overhead.
PSR-3 wrapper in your module
Then bind it in di.xml:
BrowserConsoleLogger
Outputs logs as JavaScript to the browser console. Call flush() to get the <script> block and inject it into your HTML response.
Browser output example:
Access all logs in DevTools console:
CliLogger
Outputs logs to terminal. Immediate output by default.
Terminal output:
Buffered mode (accumulate then flush):
Log Levels
All PSR-3 log levels are supported:
| Level | CLI color | Browser color | Console 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
Context values are interpolated into {placeholder} patterns in messages:
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