-
Notifications
You must be signed in to change notification settings - Fork 0
/
monolog.php
27 lines (23 loc) · 840 Bytes
/
monolog.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
<?php
require 'vendor/autoload.php';
use Monolog\Logger;
use Monolog\Formatter\LineFormatter;
use Monolog\Handler\StreamHandler;
use Monolog\Processor\PsrLogMessageProcessor;
// Create the logger
$logger = new Logger('my_logger');
$bubble = true;
$output = "%datetime% > %level_name% > %message% %context% %extra%\n";
// Create a formatter
$formatter = new LineFormatter($output);
$stream = new StreamHandler(__DIR__.'/my_app.log', Logger::INFO,$bubble);
//Configure a handler with the formatter
$stream->setFormatter($formatter);
$logger->pushHandler($stream);
$logger->pushProcessor(new PsrLogMessageProcessor());
$logger->pushProcessor(function ($record) {
$record['extra']['hello'] = 'Hello PHPMad! #phplogs';
return $record;
});
$logger->info('Info message {hello}', ['hello'=> 'holis!']);
$logger->debug('Debug message');