/** Render the current page if appropriate The page is only shown if it's accessed directly rather than through an include(). @param $custom_errors @deprecated This behavior is controlled by config variable FANNIE_CUSTOM_ERRORS. The optional parameter remains for th sake of compatibility but does not do anything. It will go away when all calls to this method have been cleaned up. */ public static function conditionalExec($custom_errors = true) { $frames = debug_backtrace(); // conditionalExec() is the only function on the stack if (count($frames) == 1) { $config = FannieConfig::factory(); $logger = new FannieLogger(); if ($config->get('SYSLOG_SERVER')) { $logger->setRemoteSyslog($config->get('SYSLOG_SERVER'), $config->get('SYSLOG_PORT'), $config->get('SYSLOG_PROTOCOL')); } $op_db = $config->get('OP_DB'); $dbc = FannieDB::get($op_db); self::setLogger($logger); // setup error logging self::setErrorHandlers(); // initialize locale & gettext self::i18n(); // draw current page $page = basename(filter_input(INPUT_SERVER, 'PHP_SELF')); $class = substr($page, 0, strlen($page) - 4); if ($class != 'index' && class_exists($class)) { $obj = new $class(); if ($dbc->isConnected($op_db)) { // write URL log self::logUsage($dbc, $op_db); /* $auth = self::authOverride($dbc, $op_db, $class); if ($auth) { $obj->setPermissions($auth); } */ } $obj->setConfig($config); $obj->setLogger($logger); if (is_a($obj, 'FannieReportPage')) { $dbc = FannieDB::getReadOnly($op_db); } $obj->setConnection($dbc); $obj->draw_page(); } else { trigger_error('Missing class ' . $class, E_USER_NOTICE); } } }
public function testLogger() { $logger = new FannieLogger(); $tempfile = tempnam(sys_get_temp_dir(), 'FLT'); $context = array('logfile' => $tempfile); $message = 'test logging'; $levels = array('emergency', 'alert', 'critical', 'error', 'warning', 'notice', 'info'); // test non-debug levels first foreach ($levels as $id => $level) { $pattern = '/^[A-Za-z]{3} \\d+ \\d\\d:\\d\\d:\\d\\d .+ fannie\\[\\d+\\]: \\(' . $level . '\\) test logging$/'; // call emergency(), alert(), etc directly unlink($tempfile); $logger->{$level}($message, $context); $output = file_get_contents($tempfile); $this->assertRegExp($pattern, $output); // call log() with string level name unlink($tempfile); $logger->log($level, $message, $context); $output = file_get_contents($tempfile); $this->assertRegExp($pattern, $output); // call log() with int level ID unlink($tempfile); $logger->log($id, $message, $context); $output = file_get_contents($tempfile); $this->assertRegExp($pattern, $output); } $pattern = '/^[A-Za-z]{3} \\d+ \\d\\d:\\d\\d:\\d\\d .+ fannie\\[\\d+\\]: \\(debug\\) test logging$/'; $frame = '/^[A-Za-z]{3} \\d+ \\d\\d:\\d\\d:\\d\\d .+ fannie\\[\\d+\\]: \\(debug\\) Frame \\#\\d+ .*, Line \\d+, function [\\w\\\\]+(::)?\\w+$/'; // test debug w/ stack trace unlink($tempfile); $logger->debug($message, $context); $output = file_get_contents($tempfile); $lines = explode("\n", $output); for ($i = 0; $i < count($lines); $i++) { if ($lines[$i] === '') { continue; } if ($i == 0) { $this->assertRegExp($pattern, $lines[$i]); } else { $this->assertRegExp($frame, $lines[$i]); } } // test debug again with an exception included in the context $e = new Exception('test exception'); $context['exception'] = $e; unlink($tempfile); $logger->debug($message, $context); $output = file_get_contents($tempfile); $lines = explode("\n", $output); for ($i = 0; $i < count($lines); $i++) { if ($lines[$i] === '') { continue; } if ($i == 0) { $this->assertRegExp($pattern, $lines[$i]); } else { $this->assertRegExp($frame, $lines[$i]); } } unlink($tempfile); }