PHPackages                             stk2k/stream-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. stk2k/stream-logger

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

stk2k/stream-logger
===================

PSR logger using php://stream stream

0.1.0(6y ago)011MITPHPPHP &gt;=7.0.0CI failing

Since Oct 12Pushed 6y ago1 watchersCompare

[ Source](https://github.com/stk2k/stream-logger)[ Packagist](https://packagist.org/packages/stk2k/stream-logger)[ Docs](https://github.com/stk2k/stream-logger)[ RSS](/packages/stk2k-stream-logger/feed)WikiDiscussions master Synced 2mo ago

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

PSR-3 logger compliant stream logger
====================================

[](#psr-3-logger-compliant-stream-logger)

[![Latest Version on Packagist](https://camo.githubusercontent.com/c52059d65c935191519926ba47252dfed36da7e2345974cd99d78744f7f5ad06/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f73746b326b2f73747265616d2d6c6f676765722e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/stk2k/stream-logger)[![Software License](https://camo.githubusercontent.com/55c0218c8f8009f06ad4ddae837ddd05301481fcf0dff8e0ed9dadda8780713e/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d627269676874677265656e2e7376673f7374796c653d666c61742d737175617265)](LICENSE.md)[![Build Status](https://camo.githubusercontent.com/246407904d3e795913aff7cb559d2f382a64a0d066f51dd1177d1b6ae73ac977/68747470733a2f2f7472617669732d63692e6f72672f73746b326b2f73747265616d2d6c6f676765722e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/stk2k/stream-logger)[![Coverage Status](https://camo.githubusercontent.com/b4410758f27c4ab5dffe300c252d41732190dee4d7890cdedd3b65744284de01/68747470733a2f2f636f766572616c6c732e696f2f7265706f732f6769746875622f73746b326b2f73747265616d2d6c6f676765722f62616467652e7376673f6272616e63683d6d6173746572)](https://coveralls.io/github/stk2k/stream-logger?branch=master)[![Code Climate](https://camo.githubusercontent.com/137492ca5f806b34567390907f539b0f42bea1c55ea1dea70aa51c209079a2bd/68747470733a2f2f636f6465636c696d6174652e636f6d2f6769746875622f73746b326b2f73747265616d2d6c6f676765722f6261646765732f6770612e737667)](https://codeclimate.com/github/stk2k/stream-logger)[![Total Downloads](https://camo.githubusercontent.com/bc25c09c43c2f33155cc52c1c5534c35753dbab5ec232bab61b3cd5b42d36fd6/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f73746b326b2f73747265616d2d6c6f676765722e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/stk2k/stream-logger)

Description
-----------

[](#description)

PSR-3 logger compliant stream logger

Feature
-------

[](#feature)

- [PSR/Log](https://github.com/php-fig/log) compliant.
- PHP output streams
    - php://stdout
    - php://stderr
    - php://output
    - php://memory
    - php://temp
- Default formatter
- Custom format with default formatter
- Custom formatter class
- toArray()/each() method to get all log messages(only for MemoryLogger).
- filter methods for buffered stream loggers.

Usage
-----

[](#usage)

### Default format

[](#default-format)

```
use Stk2k\MemoryLogger\SimpleMemoryLogger;

$logger = new SimpleMemoryLogger();
$logger->debug('Hello, world!');
$logger->warning('Something is wrong...');

print_r($logger->toArray());
// Array
// (
//     [0] => 2019-10-11 20:42:10 [debug] Hello, world! []      @...\example1.php(7)
//     [1] => 2019-10-11 20:42:10 [warning] Something is wrong... []      @...\example1.php(8)
// )
```

### Custom format with default formatter

[](#custom-format-with-default-formatter)

```
use Stk2k\MemoryLogger\SimpleMemoryLogger;
use Stk2k\MemoryLogger\Formatter\DefaultFormatter;

$logger = new SimpleMemoryLogger(new DefaultFormatter('%LEVEL%:%MESSAGE%'));
$logger->debug('Hello, world!');
$logger->warning('Something is wrong...');

print_r($logger->toArray());
// Array
// (
//     [0] => debug:Hello, world!
//     [1] => warning:Something is wrong...
// )
```

### Custom formatter class

[](#custom-formatter-class)

You can also define your own formatter by implementing LogFormatterInterface.

```
use Stk2k\MemoryLogger\SimpleMemoryLogger;
use Stk2k\MemoryLogger\LogFormatterInterface;

class JsonFormatter implements LogFormatterInterface
{
    public function format($level, $message, array $context, string $file, int $line): string
    {
        return json_encode([
            'level' => $level, 'message' => $message, 'context' => $context, 'file' => $file, 'line' => $line,
        ]);
    }
}

$logger = new SimpleMemoryLogger(new JsonFormatter);
$logger->debug('Hello, world!');
$logger->warning('Something is wrong...');

print_r($logger->toArray());
// Array
// (
//    [0] => {"level":"debug","message":"Hello, world!","context":[],"file":".../example3.php","line":18}
//    [1] => {"level":"warning","message":"Something is wrong...","context":[],"file":".../example3.php","line":19}
// )
```

### Retrieving each lines

[](#retrieving-each-lines)

```
use Stk2k\MemoryLogger\SimpleMemoryLogger;

$logger = new SimpleMemoryLogger();
$logger->debug('Hello, world!');
$logger->warning('Something is wrong...');

$logger->each(function($line){
    echo $line . PHP_EOL;
});
// 2019-10-11 20:58:33 [debug] Hello, world! []      @.../example4.php(7)
// 2019-10-11 20:58:33 [warning] Something is wrong... []      @.../example4.php(8)
```

### Filtering by log level

[](#filtering-by-log-level)

```
use Stk2k\StreamLogger\BufferedOutputLogger;
use Psr\Log\LogLevel;

$logger = new BufferedOutputLogger();

$logger->debug('debug');
$logger->warning('warning');
$logger->error('error');
$logger->notice('notice');
$logger->info('info');
$logger->critical('critical');

$logger->filterByLevelBetween(LogLevel::WARNING, LogLevel::ERROR)->flush();
// 2019-10-12 10:46:29 [warning] warning []      @.../xample6.php(10)
// 2019-10-12 10:46:29 [error] error []      @.../example6.php(11)
```

### Filtering by callback

[](#filtering-by-callback)

```
use Psr\Log\LogLevel;
use Stk2k\StreamLogger\BufferedOutputLogger;
use Stk2k\StreamLogger\LogMessage;

$logger = new BufferedOutputLogger();

$logger->debug('debug');
$logger->warning('warning');
$logger->error('error');
$logger->notice('notice');
$logger->info('info');
$logger->critical('critical');

$logger->filter(function(LogMessage $m){
    return $m->getLevel() === LogLevel::INFO || $m->getLevel() === LogLevel::WARNING;
})->flush();
// 2019-10-12 14:09:04 [warning] warning []      @.../example11.php(11)
// 2019-10-12 14:09:04 [info] info []      @.../example11.php(14)
```

Requirement
-----------

[](#requirement)

PHP 7.0 or later

Installing stk2k/stream-logger
------------------------------

[](#installing-stk2kstream-logger)

The recommended way to install stk2k/stream-logger is through [Composer](http://getcomposer.org).

```
composer require stk2k/stream-logger
```

After installing, you need to require Composer's autoloader:

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

License
-------

[](#license)

This library is licensed under the MIT license.

Author
------

[](#author)

[stk2k](https://github.com/stk2k)

Disclaimer
----------

[](#disclaimer)

This software is no warranty.

We are not responsible for any results caused by the use of this software.

Please use the responsibility of the your self.

###  Health Score

19

—

LowBetter than 10% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity2

Limited adoption so far

Community8

Small or concentrated contributor base

Maturity42

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

2402d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/955f3d564811dc5e1212c1a7a66bc4eb7e11ac166cc38600f244dc25f97d3ef4?d=identicon)[stk2k](/maintainers/stk2k)

---

Top Contributors

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

---

Tags

psr-3streamphplogger

###  Code Quality

TestsPHPUnit

### Embed Badge

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

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

###  Alternatives

[markrogoyski/simplelog-php

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

2818.1k4](/packages/markrogoyski-simplelog-php)

PHPackages © 2026

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