public static function log($message, $priority = self::INFO) { if (self::$logDirectory === FALSE) { return; } elseif (!self::$logDirectory) { throw new InvalidStateException('Logging directory is not specified in Debugger::$logDirectory.'); } if ($message instanceof Exception) { $exception = $message; $message = "PHP Fatal error: " . ($message instanceof FatalErrorException ? $exception->getMessage() : "Uncaught exception " . get_class($exception) . " with message '" . $exception->getMessage() . "'") . " in " . $exception->getFile() . ":" . $exception->getLine(); $hash = md5($exception . (method_exists($exception, 'getPrevious') ? $exception->getPrevious() : (isset($exception->previous) ? $exception->previous : ''))); $exceptionFilename = "exception " . @date('Y-m-d H-i-s') . " {$hash}.html"; foreach (new DirectoryIterator(self::$logDirectory) as $entry) { if (strpos($entry, $hash)) { $exceptionFilename = NULL; break; } } } self::$logger->log(array(@date('[Y-m-d H-i-s]'), $message, self::$source ? ' @ ' . self::$source : NULL, !empty($exceptionFilename) ? ' @@ ' . $exceptionFilename : NULL), $priority); if (!empty($exceptionFilename) && ($logHandle = @fopen(self::$logDirectory . '/' . $exceptionFilename, 'w'))) { ob_start(); ob_start(create_function('$buffer', 'extract(NClosureFix::$vars[' . NClosureFix::uses(array('logHandle' => $logHandle)) . '], EXTR_REFS); fwrite($logHandle, $buffer); '), 1); self::$blueScreen->render($exception); ob_end_flush(); ob_end_clean(); fclose($logHandle); } }
public static function log($message, $priority = self::INFO) { if (self::$logDirectory === FALSE) { return; } elseif (!self::$logDirectory) { throw new InvalidStateException('Logging directory is not specified in Debug::$logDirectory.'); } elseif (!is_dir(self::$logDirectory)) { throw new DirectoryNotFoundException("Directory '" . self::$logDirectory . "' is not found or is not directory."); } if ($message instanceof Exception) { $exception = $message; $message = "PHP Fatal error: " . ($message instanceof FatalErrorException ? $exception->getMessage() : "Uncaught exception " . get_class($exception) . " with message '" . $exception->getMessage() . "'") . " in " . $exception->getFile() . ":" . $exception->getLine(); } error_log(@date('[Y-m-d H-i-s] ') . trim($message) . (self::$source ? ' @ ' . self::$source : '') . PHP_EOL, 3, self::$logDirectory . '/' . strtolower($priority) . '.log'); if (($priority === self::ERROR || $priority === self::CRITICAL) && self::$email && @filemtime(self::$logDirectory . '/email-sent') + self::$emailSnooze < time() && @file_put_contents(self::$logDirectory . '/email-sent', 'sent')) { call_user_func(self::$mailer, $message); } if (isset($exception)) { $hash = md5($exception . (method_exists($exception, 'getPrevious') ? $exception->getPrevious() : (isset($exception->previous) ? $exception->previous : ''))); foreach (new DirectoryIterator(self::$logDirectory) as $entry) { if (strpos($entry, $hash)) { $skip = TRUE; break; } } if (empty($skip) && ($logHandle = @fopen(self::$logDirectory . "/exception " . @date('Y-m-d H-i-s') . " {$hash}.html", 'w'))) { ob_start(); ob_start(create_function('$buffer', 'extract(NClosureFix::$vars[' . NClosureFix::uses(array('logHandle' => $logHandle)) . '], EXTR_REFS); fwrite($logHandle, $buffer); '), 1); self::paintBlueScreen($exception); ob_end_flush(); ob_end_clean(); fclose($logHandle); } } }
function date($operator, $date = NULL) { if (func_num_args() === 1) { if (!preg_match('#^(?:([=<>!]=?|<>)\\s*)?(.+)$#i', $operator, $matches)) { throw new InvalidArgumentException('Invalid date predicate format.'); } list(, $operator, $date) = $matches; $operator = $operator ? $operator : '='; } $date = NTools::createDateTime($date)->format('U'); return $this->filter(create_function('$file', 'extract(NClosureFix::$vars[' . NClosureFix::uses(array('operator' => $operator, 'date' => $date)) . '], EXTR_REFS); return NTools::compare($file->getMTime(), $operator, $date); ')); }