PHPackages                             renttek/magento2-logformatters - 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. renttek/magento2-logformatters

ActiveMagento2-module[Logging &amp; Monitoring](/categories/logging)

renttek/magento2-logformatters
==============================

Utility module that adds log formatters to be used in Magento 2

1.0.0(3mo ago)01MITPHPPHP &gt;=8.3

Since Apr 25Pushed 3mo agoCompare

[ Source](https://github.com/renttek/magento2-logformatters)[ Packagist](https://packagist.org/packages/renttek/magento2-logformatters)[ RSS](/packages/renttek-magento2-logformatters/feed)WikiDiscussions main Synced 3w ago

READMEChangelogDependencies (14)Versions (2)Used By (0)

Renttek Log Formatters
======================

[](#renttek-log-formatters)

`Renttek_LogFormatters` is a small Magento 2 utility module that provides reusable Monolog formatters, decorators, and file handlers for structured logging.

All formatters in this module format the Monolog record `context`. This keeps the log output predictable and makes it easy to log structured payloads from Magento code.

Included classes
----------------

[](#included-classes)

### Formatters

[](#formatters)

- `Renttek\LogFormatters\Logger\Formatter\JsonLineFormatter`
- `Renttek\LogFormatters\Logger\Formatter\CsvFormatter`
- `Renttek\LogFormatters\Logger\Formatter\LogfmtFormatter`

### Decorators

[](#decorators)

- `Renttek\LogFormatters\Logger\Formatter\Decorator\MaskContextDecorator`
- `Renttek\LogFormatters\Logger\Formatter\Decorator\DateTimeFormatterDecorator`

### Helper formatter for decorator chains

[](#helper-formatter-for-decorator-chains)

- `Renttek\LogFormatters\Logger\Formatter\Builder\DecoratorChainFormatter`

### File handlers

[](#file-handlers)

- `Renttek\LogFormatters\Logger\Handler\JsonLineFileHandler`
- `Renttek\LogFormatters\Logger\Handler\CsvFileHandler`
- `Renttek\LogFormatters\Logger\Handler\LogfmtFileHandler`

JsonLineFormatter
-----------------

[](#jsonlineformatter)

Writes one JSON object per line.

### Example `di.xml`

[](#example-dixml)

```

        /var/log/api.log

        api

            Vendor\Module\Logger\Handler\ApiLogHandler

```

### Example output

[](#example-output)

```
{"request_id":"abc123","status":200,"path":"/rest/V1/orders"}
{"request_id":"def456","status":500,"path":"/rest/V1/orders","error":"Upstream timeout"}

```

CsvFormatter
------------

[](#csvformatter)

Writes the context values as a single CSV row. Arrays and nested structures are JSON-encoded into one cell. The `separator`, `enclosure`, and `escape` characters are configurable through the constructor and default to `,`, `"`, and `\`.

### Example `di.xml`

[](#example-dixml-1)

```

        /var/log/export.csv
        ;
        "
        \

        export

            Vendor\Module\Logger\Handler\ExportLogHandler

```

### Example output

[](#example-output-1)

```
2026-04-25T13:45:00+00:00;orders;150;2
2026-04-25T13:50:00+00:00;customers;80;0

```

LogfmtFormatter
---------------

[](#logfmtformatter)

Writes the context as `key=value` pairs in logfmt format. Values with spaces or special characters are quoted.

### Example `di.xml`

[](#example-dixml-2)

```

        /var/log/sync.logfmt

        sync

            Vendor\Module\Logger\Handler\SyncLogHandler

```

### Example output

[](#example-output-2)

```
job=inventory_sync status=ok duration_ms=231 store=default
job=inventory_sync status=failed duration_ms=912 error="Connection reset by peer"

```

MaskContextDecorator
--------------------

[](#maskcontextdecorator)

Decorates another formatter and replaces configured context fields with a fixed mask value before the wrapped formatter formats the record.

### Example `di.xml`

[](#example-dixml-3)

```

        Renttek\LogFormatters\Logger\Formatter\JsonLineFormatter

            authorization
            token
            password

        [redacted]

```

### Example output

[](#example-output-3)

```
{"endpoint":"/rest/V1/customers","authorization":"[redacted]","token":"[redacted]","customer_id":42}
{"endpoint":"/rest/V1/customers","password":"[redacted]","email":"customer@example.com"}

```

DateTimeFormatterDecorator
--------------------------

[](#datetimeformatterdecorator)

Decorates another formatter and converts any `DateTimeInterface` values in the context to strings before the wrapped formatter formats the record. The output format is configurable and defaults to `DATE_ATOM`.

### Example `di.xml`

[](#example-dixml-4)

```

        Renttek\LogFormatters\Logger\Formatter\JsonLineFormatter
        Y-m-d H:i:s

```

### Example output

[](#example-output-4)

```
{"job":"catalog_sync","started_at":"2026-04-25 14:30:00","finished_at":"2026-04-25 14:31:15"}

```

DecoratorChainFormatter
-----------------------

[](#decoratorchainformatter)

`DecoratorChainFormatter` helps keep `di.xml` flatter when you want to apply multiple decorators to one formatter. You provide one base formatter and a list of decorator configurations. Decorators are applied in the same order as they are listed in `di.xml`.

### Example `di.xml`

[](#example-dixml-5)

```

        Renttek\LogFormatters\Logger\Formatter\JsonLineFormatter

            Renttek\LogFormatters\Logger\Formatter\Decorator\DateTimeFormatterDecorator

                Renttek\LogFormatters\Logger\Formatter\Decorator\MaskContextDecorator

                    token
                    authorization

                [redacted]

        /var/log/api.log
        Vendor\Module\Logger\Formatter\ApiFormatter

```

### Example output

[](#example-output-5)

```
{"endpoint":"/rest/V1/orders","requested_at":"2026-04-25T14:30:00+00:00","authorization":"[redacted]","token":"[redacted]"}

```

Notes
-----

[](#notes)

- The file handlers write to Magento's `var/log` directory when you pass a path such as `/var/log/example.log` as `fileName`.
- The JSON, CSV, and logfmt handlers accept an optional `formatter` constructor argument, so decorated formatters can be injected through `di.xml`.
- `CsvFileHandler` also accepts `separator`, `enclosure`, and `escape` constructor arguments.

###  Health Score

37

—

LowBetter than 81% of packages

Maintenance82

Actively maintained with recent releases

Popularity2

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity49

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

Unknown

Total

1

Last Release

90d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/1931090?v=4)[Julian](/maintainers/renttek)[@renttek](https://github.com/renttek)

---

Top Contributors

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

###  Code Quality

Static AnalysisPHPStan, Rector

Code StyleECS

Type Coverage Yes

### Embed Badge

![Health badge](/badges/renttek-magento2-logformatters/health.svg)

```
[![Health](https://phpackages.com/badges/renttek-magento2-logformatters/health.svg)](https://phpackages.com/packages/renttek-magento2-logformatters)
```

###  Alternatives

[graycore/magento2-stdlogging

A Magento 2 module that changes all logging handlers to stdout

2587.9k](/packages/graycore-magento2-stdlogging)[mage-os/module-admin-activity-log

The Admin Activity extension makes it easy to track all admin activity with comprehensive audit logging.

296.3k1](/packages/mage-os-module-admin-activity-log)[fredden/magento2-module-javascript-error-reporting

A Magento 2 module which captures JavaScript errors for later review by website administrators

3139.8k](/packages/fredden-magento2-module-javascript-error-reporting)[myparcelnl/magento

A Magento 2 module that creates MyParcel labels

1860.2k](/packages/myparcelnl-magento)[graycore/magento2-graphql-logger

118.0k](/packages/graycore-magento2-graphql-logger)[loki/magento2-components

Core module for defining Alpine.js components with advanced AJAX features

1011.8k26](/packages/loki-magento2-components)

PHPackages © 2026

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