/** * Log message into file, notify the admin on stagging/production * * @param mixed $messages messages to log */ public static function log($messages) { $config = \Phalcon\DI::getDefault()->getShared('config'); $dump = new Dump(); if ($config->app->env == "development") { foreach ($messages as $key => $message) { echo $dump->one($message, $key); } exit; } else { $logger = new \Phalcon\Logger\Adapter\File(APP_PATH . '/app/common/logs/' . date('Ymd') . '.log', array('mode' => 'a+')); $log = ''; if (is_array($messages) || $messages instanceof \Countable) { foreach ($messages as $key => $message) { if (in_array($key, array('alert', 'debug', 'error', 'info', 'notice', 'warning'))) { $logger->{$key}($message); } else { $logger->log($message); } $log .= $dump->one($message, $key); } } else { $logger->log($messages); $log .= $dump->one($messages); } if ($config->app->env != "testing") { $email = new Email(); $email->prepare(__('Something is wrong!'), $config->app->admin, 'error', array('log' => $log)); if ($email->Send() !== true) { $logger->log($email->ErrorInfo); } } $logger->close(); } }
protected function tearDown() { parent::tearDown(); // reset output flag to default \Phalcon\Debug\Dump::setOutput(true); // reset PHP_SAPI \Phalcon\Debug\Dump::setSapi(PHP_SAPI); }