You can use debug_backtrace().
http://us3.php.net/manual/en/function.debug-backtrace.php
So, in your log function, you would be able to retrieve the filename and line number from which the log function was called.
I’m using this approach in my logging classes and it has significantly reduced the amount of code required to get meaningful log data. Another benefit would be readability. Magic constants tend to get quite ugly when mixed with strings.
Here’s a quick example:
function log($msg)
{
$bt = debug_backtrace();
$caller = array_shift($bt);
// echo $caller['file'];
// echo $caller['line'];
// do your logging stuff here.
}