I want a way to log the beginning and end of the function call without explicitly making a call to a method in log object.
I know we can use xdebug to trace the flow, but I have a requirement where I have to make the functions call to be written in the log file without (having code) calling $logObj->info('Function call');.
For ex:
<?php
class something
{
public function test()
{
echo "Test.";
}
}
$some = new something();
$some->test();
?>
Now, I want to see the following entries in my out.log:
2010-08-03T09:06:15+02:00 ERR (1): Entering something::test()
...
...
2010-08-03T09:06:15+02:00 ERR (1): Leaving something::test()
What you need is AOP ( http://en.wikipedia.org/wiki/Aspect-oriented_programming )
But PHP doesn’t support AOP natively (there are some extensions for it, but I don’t know how good they are).
As troelskn mentioned, you should create a wrapper class (untested):