Jump to content

Pear Logger trouble


Braclayrab

Recommended Posts

Hi, i'm trying to use the pear logger to simply log some data to a file.
When I make a test script it works fine:

require_once($_SERVER["SITE_HTMLROOT"].'/Include/MyLogger.php');
$myLogger->log("foo error", PEAR_LOG_ERR);//This works

Contents of MyLogger.php:

<?php
require_once 'Log.php';//the Pear Logger
$myLogger = &Log::singleton("file", $_SERVER["SITE_HTMLROOT"]."/my.log");
?>

However, when I try to use $myLogger from within a class member-function I get an error:

"Call to a member function log() on a non-object in /home/10213/domains/mrmoviepants.com/html/Include/RSA.php on line 345"

As you can see, i'm trying to debug the Pear RSA Library but I don't believe that in particular is relevant.  Any ideas?

Thanks in advance!
-Clay

UPDATE:
I wrote another quick test script:

<?php
require_once("testinclude.php");
echo($testvar);
Class testfoo
{
function test()
{
//echo($testvar);
if(isSet($testvar))
{
echo($testvar);
}
else
{
echo("cannot find testvar<BR>");
}
}
}
$myFoo = new testfoo();
$myFoo->test();
?>

testinclude.php:

<?php
$testvar = "this is my testvar<BR>";
?>

output:

"this is my testvar
cannot find testvar"

Is it not possible to access variables outside of a class from inside a member function?  I suppose that does makes sense. 
I think I'm going to try giving my class and errorhandler...
Link to comment
Share on other sites

UPDATE:
this works:
$error_handler = create_function('$obj', 'echo("error: ". $obj->getLastError()->getMessage(). "<BR>");');

this does not:
$error_handler = create_function('$obj', '$myLogger->log("error: ". $obj->getLastError()->getMessage(). "<BR>",PEAR_LOG_ERR);');

I get the same error:
"Fatal error: Call to a member function log() on a non-object in /home/10213/domains/mrmoviepants.com/html/Admin/test2.php(41) : runtime-created function on line 1"

How can I access myLogger from within a class?  help!!

Link to comment
Share on other sites

Update(i'm retarded):

function logError($obj)
{
$myLogger = &Log::singleton("file", $_SERVER["SITE_HTMLROOT"]."/my.log");
$myLogger->log("error: ". $obj->getLastError()->getMessage(). "<BR>",PEAR_LOG_ERR);
}
$rsa_obj = new Crypt_RSA;
$rsa_obj->setErrorHandler(logError);

this works, obviously.  I suppose I could have done this inline as well.
I hope this thread helps someone else.  >.<
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.