/** * Logs with an arbitrary level. * * @param string $uClass * @param mixed $uLevel * @param array $uContext * @return null */ public static function write($uClass, $uLevel, array $uContext = array()) { if (!isset($uContext['type'])) { $uContext['type'] = $uLevel === LogLevel::DEBUG || $uLevel === LogLevel::INFO ? 'log' : 'error'; } self::$typeCounts[$uContext['type']]++; $uContext['class'] = $uClass; $uContext['category'] = $uLevel; $uContext['ip'] = $_SERVER['REMOTE_ADDR']; if (isset($uContext['message'])) { $uContext['message'] = String::prefixLines($uContext['message'], '- ', PHP_EOL); } if (isset($uContext['file'])) { if (Framework::$development) { $uContext['location'] = Io::extractPath($uContext['file']); if (isset($uContext['line'])) { $uContext['location'] .= ' @' . $uContext['line']; } } else { $uContext['location'] = pathinfo($uContext['file'], PATHINFO_FILENAME); } } else { $uContext['location'] = '-'; } $uContext['stackTrace'] = array(); foreach (array_slice(debug_backtrace(), 2) as $tFrame) { $tArgs = array(); /* if (isset($tFrame['args'])) { foreach ($tFrame['args'] as $tArg) { $tArgs[] = var_export($tArg, true); } } */ if (isset($tFrame['class'])) { $tFunction = $tFrame['class'] . $tFrame['type'] . $tFrame['function']; } else { $tFunction = $tFrame['function']; } if (isset($tFrame['file'])) { if (Framework::$development) { $tLocation = Io::extractPath($tFrame['file']); if (isset($tFrame['line'])) { $tLocation .= ' @' . $tFrame['line']; } } else { $tLocation = pathinfo($tFrame['file'], PATHINFO_FILENAME); } } else { $tLocation = '-'; } $uContext['stackTrace'][] = $tFunction . '(' . implode(', ', $tArgs) . ') in ' . $tLocation; } $uContext['eventDepth'] = Events::$eventDepth; Events::$disabled = true; if (!Framework::$readonly) { $tContent = '+ ' . String::format(Logger::$line, $uContext); $tFilename = Io::translatePath('{writable}logs/' . String::format(Logger::$filename, $uContext), true); Io::write($tFilename, $tContent, LOCK_EX | FILE_APPEND); } self::$console[] = $uContext; Events::$disabled = false; if (isset($uContext['halt']) && $uContext['halt']) { Events::invoke('reportError', $uContext); Framework::end(-1); } }
/** * Output callback method which will be called when the output buffer * is flushed at the end of the request. * * @param string $uValue the generated content * @param int $uStatus the status of the output buffer * * @return string final content */ public static function output($uValue, $uStatus) { $tParms = array('exitStatus' => &self::$exitStatus, 'responseFormat' => &self::$responseFormat, 'content' => &$uValue); Events::invoke('output', $tParms); if (ini_get('output_handler') === "") { $tParms['content'] = mb_output_handler($tParms['content'], $uStatus); // PHP_OUTPUT_HANDLER_START | PHP_OUTPUT_HANDLER_END if (!ini_get('zlib.output_compression') && PHP_SAPI !== 'cli' && Config::get('options/gzip', true) === true) { $tParms['content'] = ob_gzhandler($tParms['content'], $uStatus); // PHP_OUTPUT_HANDLER_START | PHP_OUTPUT_HANDLER_END } } return $tParms['content']; }