2

私はphpで軽量のロギングクラスを書いています。$__LINE__Logクラスの関数が呼び出されているファイル名/関数/行番号を自動的に記録し、ユーザーが関数を$__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のソリューションを見ましたが、私が望むものにはかなり重いようです。

4

2 に答える 2

2

debug_backtrace関数を見てください。必要なすべての情報が提供されているように見えます。

function, line, file, class, object, type, args
于 2009-12-10T12:16:18.453 に答える
1

マジック定数:http ://www.php.net/manual/en/language.constants.predefined.php

于 2009-12-10T12:20:01.567 に答える