Skip to content

Instantly share code, notes, and snippets.

@dave1010
Created April 22, 2014 12:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dave1010/11176348 to your computer and use it in GitHub Desktop.
Save dave1010/11176348 to your computer and use it in GitHub Desktop.
Make sure a Monolog logger can log
<?php
$handler = new RotatingFileHandler(ABSPATH . '../logs/log.log', 0, Logger::DEBUG, true, 0777);
try {
$record = array(
'message' => (string) "Write test",
'context' => null,
'level' => Logger::DEBUG,
'level_name' => 'DEBUG',
'channel' => 'online-topups',
'datetime' => \DateTime::createFromFormat('U.u', sprintf('%.6F', microtime(true)), new DateTimeZone('UTC'))->setTimezone(new DateTimeZone('UTC')),
'extra' => array(),
);
$handler->handle($record);
} catch (UnexpectedValueException $e) {
error_log('switching logger');
$handler = new \Monolog\Handler\NullHandler;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment