Skip to content

Instantly share code, notes, and snippets.

@witwall
Last active November 30, 2015 02:59
Show Gist options
  • Save witwall/7871a9b1fbfa4eff56d2 to your computer and use it in GitHub Desktop.
Save witwall/7871a9b1fbfa4eff56d2 to your computer and use it in GitHub Desktop.
<?PHP
require __DIR__ . '/vendor/autoload.php';

$log = new Monolog\Logger('name');
$log->pushHandler(new Monolog\Handler\StreamHandler('app.log', Monolog\Logger::WARNING));
$log->addWarning('Foo');
?>
php monolog_test.php

got error,

Fatal error: Uncaught exception 'Exception' with message 'DateTime::__construct(): It is not safe to rely on the system's timezone settings. You are *required* to use the date.timezone setting or the date_default_timezone_set() function. In case you used any of those methods and you are still getting this warning, you most likely misspelled the timezone identifier. We selected the timezone 'UTC' for now, but please set date.timezone to select your timezone.' in /Users/steven/tmp/composer_test/vendor/monolog/monolog/src/Monolog/Logger.php:171
Stack trace:
#0 /Users/steven/tmp/composer_test/vendor/monolog/monolog/src/Monolog/Logger.php(171): DateTime->__construct()
#1 /Users/steven/tmp/composer_test/vendor/monolog/monolog/src/Monolog/Logger.php(231): Monolog\Logger->addRecord(300, 'Foo', Array)
#2 /Users/steven/tmp/composer_test/test.php(8): Monolog\Logger->addWarning('Foo')
#3 {main}
  thrown in /Users/steven/tmp/composer_test/vendor/monolog/monolog/src/Monolog/Logger.php on line 171

solution,

  • Your PHP.ini needs to have the date.timezone setting
  • You can also add the setting to your .htaccess file php_value date.timezone America/Los_Angeles
  • or using date_default_timezone_set("America/Los_Angeles"); in you PHP script
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment