PHP Classes
Icontem

Log class


  Search   All class groups All class groups   Latest entries Latest entries   Top 10 charts Top 10 charts   Newsletter Newsletter   Blog Blog   Forums Forums   Help FAQ Help FAQ  
  Login   Register  
Recommend this page to a friend! ReTweet ReTweet Stumble It! Stumble It! Bookmark in del.icio.us Bookmark in del.icio.us

      Top level forums  >  PHP Specialists  >  General  >  Log class  
Subject:Log class
Summary:It doesn't incremenent the variable
Messages:11
Author:Robert Stefan
Date:2009-11-04 14:56:33
Update:2009-11-05 17:59:27
 

  1. Log class   Reply  
Picture of Robert Stefan
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.

There are 10 replies in this thread, which are not being displayed.
Browsing this forum thread replies is available only to premium subscribers.


Go to the premium subscriptions page to learn how to become a premium subscriber and have full access to this forum.


 
  Advertise on this site Advertise on this site   Site map Site map   Statistics Statistics   Site tips Site tips   Privacy policy Privacy policy   Contact Contact  

For more information send a message to :
info at phpclasses dot org.
Copyright (c) Icontem 1999-2009 PHP Classes - PHP Class Scripts
  PHP Book Reviews - Reviews of books and other products