[PHP-DB] Re: [PHP] Adding a log file

2003-11-07 Thread John W. Holmes
Erik Osterman wrote:

Consider using this

//
// STDERR logging function
//
function warn( $msg, $die = 0 )
{
$fp = fopen(php://stderr, 'w') or die(Failed to open STDERR);
fwrite($fp, [.strftime(%Y-%m-%d %T).] $msg\n) 
			or die(Failed to write to stderr);
fclose($fp);
if($die)
die($msg);
}
There is also the error_log() and syslog() functions.

http://us2.php.net/error_log
http://us2.php.net/syslog
--
---John Holmes...
Amazon Wishlist: www.amazon.com/o/registry/3BEXC84AB3A5E/

php|architect: The Magazine for PHP Professionals  www.phparch.com

--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[PHP-DB] RE: [PHP] Adding a log file

2003-11-07 Thread Erik Osterman
Consider using this

//
// STDERR logging function
//
function warn( $msg, $die = 0 )
{
$fp = fopen(php://stderr, 'w') or die(Failed to open STDERR);
fwrite($fp, [.strftime(%Y-%m-%d %T).] $msg\n) 
or die(Failed to write to stderr);
fclose($fp);
if($die)
die($msg);
}
  

This function will log all output to your Apache BASE error log. It's kind
of like Perl's warn function for PHP.


Also, it's good practice to use assertions... look into assert at
http://php.net/assert

Here is some sample usage...

assert_options (ASSERT_ACTIVE, 1);
assert_options (ASSERT_WARNING, 0);
assert_options (ASSERT_QUIET_EVAL, 1);
assert_options (ASSERT_BAIL, 1);
 
// Create a handler function
function assert_callback ($file, $line, $code) {
$body = file($file);
if(empty($code))
$code = trim($body[$line-1]);
print hrfont color=redAssertion Failed:/fontbrul
File '$file'br
Line '$line'br
Code '$code'br/ul;
warn(Assertion failed ($code) in $file on line $line '$code');
print hr;
}
 
// Set up the callback
assert_options (ASSERT_CALLBACK, 'assert_callback');



Regards,

Erik Osterman
http://osterman.com/


 


-Original Message-
From: Robert Sossomon [mailto:[EMAIL PROTECTED] 
Sent: Wednesday, November 05, 2003 7:38 AM
To: [EMAIL PROTECTED]; [EMAIL PROTECTED]
Subject: [PHP] Adding a log file

I am seeing some errors with a program I wrote and I need to write
everything to a log file that the program is doing.

The following syntax I KNOW is wrong, but not sure they are important to
put here correctly yet.
//script addtocart
$Addcart (info1, info2)
Mysqlquey($addcart)

I am seeing random items NOT being added to my shopping cart.  The
reason, I have no clue. I can pull another catgory of items and the
first 20 will do fine, I go back to the first category I have and the
script seems to work correctly but the data is not written to the
shopping cart.  Problem with the shopping cart???  I wouldn't think so.
Problem with the add page, I don't see how.  So where is the error
coming from?  No clue, which is why I want to log everything.  I use 3
different add pages so that each form uses a different way to add.  This
works for me, and seems to work rather well.  But I need to log
everything on the 3 forms to see where the errors are coming from.

TIA!

Robert
~~~
To rest is to rust. 
~~~

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

-- 
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php