我写在PHP轻质日志类。 如何自动记录文件名/功能/行,其中在日志类的功能正在从被叫号码并保存行数和时间的东西,而让我的用户不屑于进入$__LINE__$__FILE__每次调用该函数的时间。有什么我可以叫隐

示例:

class Log {
static private $instance;
static $logfile;
private function __construct(){
    // doesn't need to do anything
    // one logging object to avoid/control future/potential race conditions
}
public function getInstance(){
    if(!Self::$instance) {
        Self::$instance = new Log();
    } else {
        return Self::$instance;
    }
}

public function criticalLog($string){
    // I want this to be logging line number, filename

}
}

现在我希望能够像在说文件api.php行数15

logInstance.criticalLog("This log is important");

在我的日志文件,我想看看

12/10/09-11:15 api.php 15 This log is important

任何想法?我看了一下PEAR和log4php解决方案,但他们似乎对我想要的东西相当沉重的。

有帮助吗?

解决方案

看一看的 debug_backtrace 功能,它会出现它提供了你需要的所有信息:

function, line, file, class, object, type, args
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top