Skip to content

Instantly share code, notes, and snippets.

@wowo
Last active Sep 3, 2019
Embed
What would you like to do?
log-demo

Installation:

git clone git@gist.github.com:936078e0b626122aee71a242539dfa47.git log-demo
cd log-demo
composer install
php index.php
{
"name": "wowo/log-demo",
"type": "project",
"require": {
"monolog/monolog": "^2.0"
},
"authors": [
{
"name": "Wojciech Sznapka",
"email": "wojciech@sznapka.pl"
}
]
}
<?php
require __DIR__.'/vendor/autoload.php';
use Monolog\Logger;
use Monolog\Handler\StreamHandler;
use Monolog\Processor\MemoryPeakUsageProcessor;
use Monolog\Processor\MemoryUsageProcessor;
$log = new Logger(basename(__DIR__));
$log
->pushHandler(new StreamHandler('php://stdout', Logger::INFO))
->pushProcessor(new MemoryUsageProcessor())
->pushProcessor(new MemoryPeakUsageProcessor());
$log->info('Starting');
$randomNumbers = [];
for ($i = 0; $i < 1234567; $i++) {
$randomNumbers[] = rand();
}
$log->info('Got 1st batch of numbers');
unset($randomNumbers);
$randomNumbers = [];
$log->info('Erased');
for ($i = 0; $i < 2 * 1234567; $i++) {
$randomNumbers[] = rand();
}
$log->info('Got 2nd batch of numbers');
echo '¯\_(ツ)_/¯' . PHP_EOL;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment