<?php
require_once '../vendor/autoload.php';
use Ite\Logger\FileLogger;
use Ite\Logger\LoggerAggregator;
use Ite\Logger\PhpMailLogger;
// create some simple loggers:
$logger = new FileLogger(['error' => '../data/logs/errors.log', 'alert' => '../data/logs/errors.log']);
$logger2 = new FileLogger();
$logger3 = new FileLogger();
$logger3->setDefaultLog('../data/logs/all.log');
// Change the email addres to yours:
$emailLogger = new PhpMailLogger('me@xample.com');
// create Logger Aggregator with a nested logger for 'error' and 'alert' level:
$loggerAggregator = new LoggerAggregator(['error' => $logger, 'alert' => $logger]);
// attach logger for 'info', 'debug' and 'error' levels:
$loggerAggregator->attachLogger($logger2, ['info', 'debug', 'error']);
// attach logger for all log levels:
$loggerAggregator->attachLogger($logger3);
// remove a logger for 'debug' level:
$loggerAggregator->detachLogger($logger2, 'debug');
// add email logger for critical messages:
$loggerAggregator->attachLogger($emailLogger, 'critical');
// fire some loggings:
for ($i=0; $i<10; $i++) {
$loggerAggregator->info("Test info {$i}",['a' => 'test context', 'qwe' => 'alabala']);
}
for ($i=0; $i<10; $i++) {
$loggerAggregator->error("Test error {$i}", ['exception' => new Exception("Tesitng exceptions")]);
}
for ($i=0; $i<10; $i++) {
$loggerAggregator->alert("Test alert {$i}", ['exception' => new Exception("Tesitng exceptions"),'a' => 'test context', 'qwe' => 'alabala']);
}
for ($i=0; $i<10; $i++) {
$loggerAggregator->debug("Test debug {$i}");
}
// Fire criticial log message (this should send email):
$loggerAggregator->critical("Critical message");
|