PHP Classes

File: examples/file_logger.php

Recommend this page to a friend!
  Classes of Kiril Savchev   ITE Logger   examples/file_logger.php   Download  
File: examples/file_logger.php
Role: Example script
Content type: text/plain
Description: Example script
Class: ITE Logger
Log messages to different storage PSR-3 compliant
Author: By
Last change:
Date: 7 years ago
Size: 898 bytes
 

Contents

Class file image Download
<?php

require_once '../vendor/autoload.php';

// Create the file logger with concrete log fils for 'alert' and 'error' levels:
$logger = new \Ite\Logger\FileLogger([
       
'error' => '../data/logs/errors.log',
       
'alert' => '../data/logs/errors.log'
]);
// the rest of levels will use the default log file

// log 10 info messages with fake context:
for ($i=0; $i<10; $i++) {
       
$logger->info("Test info {$i}",['a' => 'test context', 'qwe' => 'alabala', 'q' => [1, 2, 4]]);
}
// log 10 error messages with exception:
for ($i=0; $i<10; $i++) {
       
$logger->error("Test error {$i}", ['exception' => new Exception("Tesitng exceptions")]);
}
// log 10 alert messages with exception and fake context:
for ($i=0; $i<10; $i++) {
       
$logger->alert("Test alert {$i}", ['exception' => new Exception("Tesitng exceptions"), 'a' => 'test context', 'qwe' => 'alabala', 'q' => [1, 2, 4]]);
}