Source for file errorlogviewer.php
Documentation is available at errorlogviewer.php
* Shows simple usage of SaxFilters to parse an XML error log
# require_once 'XML/SaxFilters.php'; // This is the normal way to do it
# Done to help development
if ( !@include_once 'XML/SaxFilters.php' ) {
define ('XML_SAXFILTERS', '../../');
include_once XML_SAXFILTERS . 'SaxFilters.php';
if ($argc < 2 || in_array($argv[1 ], array ('--help', '-help', '-h', '-?'))) {
Usage: <?php echo $argv[0 ]; ?> <log_filename>
<log_filename>: name of the log file to parse
<level>: PHP error level to filter for e.g. E_USER_WARNING
<error_script>: name of PHP script where error occurred
<message>: string to compare with error messages
if (version_compare(phpversion(), '4.3.0', '<') ||
php_sapi_name() == 'cgi') {
define('STDOUT', fopen('php://stdout', 'w'));
define('STDERR', fopen('php://stderr', 'w'));
register_shutdown_function(
create_function('', 'fclose(STDOUT); fclose(STDERR); return true;'));
//---------------------------------------------------------------------
// Define a customer handler class - just displays stuff
class LogFilter extends XML_SaxFilters_AbstractFilter {
var $displayError = TRUE;
function LogFilter($filename,$level=NULL,$errorscript=NULL,$message=NULL) {
$this->filename = $filename;
if ( $errorscript ) $this->errorscript = $errorscript;
if ( $message ) $this->message = $message;
fwrite(STDOUT,"Parsing {$this->filename}\n\n");
function open(& $tag,& $attribs) {
$this->child->open($tag,$attribs);
} else if ( strtolower($tag) == 'error' ) {
$this->displayError = TRUE;
if ( strtolower($tag) == 'error' ) {
if ( $this->displayError ) {
fwrite(STDOUT,$this->buffer."\n");
$this->child->close($tag);
$this->displayError = $this->displayError & $this->child->data($data);
$this->buffer.= $data . ' ';
fwrite(STDOUT,"\nParsing complete\n");
//---------------------------------------------------------------------
class ErrorLevelFilter extends XML_SaxFilters_AbstractFilter {
function ErrorLevelFilter($level = NULL) {
if ( in_array($level,$levels) ) $this->level = $level;
function open(& $tag,& $attribs) {
if ( strtolower($tag) == 'level' ) {
$this->child->open($tag,$attribs);
if ( strtolower($tag) == 'level' ) {
$this->child->close($tag);
if ( $this->level == $data ) {
return $this->child->data($data);
//---------------------------------------------------------------------
class ErrorScriptFilter extends XML_SaxFilters_AbstractFilter {
function ErrorScriptFilter($errorscript = NULL) {
if ( $errorscript ) $this->errorscript = $errorscript;
function open(& $tag,& $attribs) {
if ( strtolower($tag) == 'file' ) {
$this->child->open($tag,$attribs);
if ( strtolower($tag) == 'file' ) {
$this->child->close($tag);
if ( $this->errorscript ) {
if ( !strpos ( $data, $this->errorscript ) === FALSE ) {
return $this->child->data($data);
//---------------------------------------------------------------------
class MessageFilter extends XML_SaxFilters_AbstractFilter {
function ErrorScriptFilter($message = NULL) {
if ( $message ) $this->message = $message;
function open(& $tag,& $attribs) {
if ( strtolower($tag) == 'message' ) {
$this->child->open($tag,$attribs);
if ( strtolower($tag) == 'message' ) {
$this->inMessage = FALSE;
$this->child->close($tag);
if ( $this->inMessage ) {
if ( FALSE !== strpos ( $data, $this->message ) ) {
return $this->child->data($data);
//---------------------------------------------------------------------
//---------------------------------------------------------------------
class PassThruFilter extends XML_SaxFilters_AbstractFilter {
//---------------------------------------------------------------------
$parser = & XML_SaxFilters_createParser('Expat','File',$logfile);
$opts = array('l'=>NULL,'s'=>NULL,'m'=>NULL);
$args = array_slice($argv,2);
foreach ( $args as $arg ) {
if ( strpos($arg,'-') === 0 ) {
$arg = explode('=',$arg);
if ( array_key_exists($arg[0],$opts) ) {
$opts[$arg[0]] = $arg[1];
$filters[]= & new LogFilter($logfile);
if ( isset($opts['l']) ) {
$filters[]= & new ErrorLevelFilter($opts['l']);
if ( isset($opts['s']) ) {
$filters[]= & new ErrorScriptFilter($opts['s']);
if ( isset($opts['m']) ) {
$filters[]= & new MessageFilter($opts['m']);
$filters[]= & new PassThruFilter();
XML_SaxFilters_buildChain($parser,$filters);
if ( ! $parser->parse() ) {
$error = $parser->getError();
fwrite (STDERR,$error->getMessage());
Documentation generated on Mon, 11 Mar 2019 10:15:10 -0400 by phpDocumentor 1.4.4. PEAR Logo Copyright © PHP Group 2004.
|