Robert Stefan - 2009-11-04 16:50:36
I've coded a Log class that outputs the errors in a xml document. If there are multiple errors that have occured in the present day, it appends the new set of information at the end of the file and the logs are separated by <entry_no>no</entry_no>.
The problem that keeps bothering me is that I cannot make the variable that will output the entry_no to increment each time the function is triggered.
Here is the code that I have:
public function beta_writeLog($file, $namespace, $class, $function, $line, $error, $errno)
{
global $doc;
$val = self::$x++;
$now = date ( "Y-m-d H:i:s" );
if (file_exists ( date ( 'Y-m-d' ) . '_log.xml' ))
{
$doc->load ( date ( 'Y-m-d' ) . '_log.xml' );
$root = $doc->documentElement;
}
else
{
$root = $doc->createElement ( 'error_entry' );
$doc->appendChild ( $root );
}
$prop = $doc->createElement ( 'entry_nr' );
$root->appendChild ( $prop );
$nr = $doc->createTextNode ( $val );
$prop->appendChild ( $nr );
$date = $doc->createElement ( 'date' );
$root->appendChild ( $date );
$date_value = $doc->createTextNode ( $now );
$date->appendChild ( $date_value );
$file_ = $doc->createElement ( 'file' );
$root->appendChild ( $file_ );
$file_nm = $doc->createTextNode ( $file );
$file_->appendChild ( $file_nm );
$namespace_ = $doc->createElement ( 'namespace' );
$root->appendChild ( $namespace_ );
$namespace_nm = $doc->createTextNode ( $namespace );
$namespace_->appendChild ( $namespace_nm );
$class_ = $doc->createElement ( 'class' );
$root->appendChild ( $class_ );
$class_nm = $doc->createTextNode ( $class );
$class_->appendChild ( $class_nm );
$function_ = $doc->createElement ( 'function' );
$root->appendChild ( $function_ );
$function_nm = $doc->createTextNode ( $function );
$function_->appendChild ( $function_nm );
$line_ = $doc->createElement ( 'line' );
$root->appendChild ( $line_ );
$line_no = $doc->createTextNode ( $line );
$line_->appendChild ( $line_no );
$error_ = $doc->createElement ( 'error' );
$root->appendChild ( $error_ );
$error_msg = $doc->createTextNode ( $error );
$error_->appendChild ( $error_msg );
$error_ = $doc->createElement ( 'errno' );
$root->appendChild ( $error_ );
$error_no = $doc->createTextNode ( $errno );
$error_->appendChild ( $error_no );
$this->save ( date ( 'Y-m-d' ) );
}
The variable $x is declared as static and the default value is 1.
Does anybody know how to solve this problem? Thank's in advance.