-
-
Save lisaross/d36f1132ad9b17cef05a212ebd4bdc47 to your computer and use it in GitHub Desktop.
Example use of Monolog logger
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// Before: composer require monolog/monolog | |
// composer autoloader | |
require_once 'vendor/autoload.php'; | |
// Shortcuts for simpler usage | |
use \Monolog\Logger; | |
use \Monolog\Formatter\LineFormatter; | |
use \Monolog\Handler\StreamHandler; | |
// Common logger | |
$log = new Logger('files'); | |
// Line formatter without empty brackets in the end | |
$formatter = new LineFormatter(null, null, false, true); | |
// Debug level handler | |
$debugHandler = new StreamHandler('debug.log', Logger::DEBUG); | |
$debugHandler->setFormatter($formatter); | |
// Error level handler | |
$errorHandler = new StreamHandler('error.log', Logger::ERROR); | |
$errorHandler->setFormatter($formatter); | |
// This will have both DEBUG and ERROR messages | |
$log->pushHandler($debugHandler); | |
// This will have only ERROR messages | |
$log->pushHandler($errorHandler); | |
// The actual logging | |
$log->debug('I am debug'); | |
$log->error('I am error', array('productId' => 123)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment