Tamam Günlük Kaydı Sınıfım için başka bir soru HERE var, ancak çağıran komut dosyasının satır numarasını günlük dosyası girdisine ekleyebilmeyi istedim.PHP, günlüğe kaydetme olayından satır numarası olsun
__Line __ görmüştüm ama bu bana bunun olduğu satırın satır numarasını verir.
Örnek:
a.php debug benim Logger.php sınıfında Şimdi
$log = new Logger();
$log->debug('hello'); // Say this is line #20
() Ben örnek hat # 300 üzerinde Sihirli Constant __ __Line kullanın. Komut dosyasını çalıştırdığımda, günlük girişinin '20 satırında' okumasını istiyorum, ancak '300 satırında' okudu. Hat numarasını fonksiyona aktarmanın yanı sıra bunu yapabileceğim başka bir yol var mı?
Örnek ayıklama sınıfı fonksiyonu
public function debug($message) {
if(DEBUG) {
$this->calling_script = $this->getScriptBaseName();
$this->log_file = LOG_FILE_DIRECTORY."/".$this->calling_script.".log";
$this->fh = fopen($this->log_file, 'a') or die("Can't open log file: ".$this->log_file);
if($this->first_run) {
$this->log_entry = "\n[" . date("Y-m-d H:i:s", mktime()) . "][debug][line:".__LINE__."]:\t".$message."\n";
} else {
$this->log_entry = "[" . date("Y-m-d H:i:s", mktime()) . "][debug][line:".__LINE__."]:\t".$message."\n";
}
fwrite($this->fh, $this->log_entry);
fclose($this->fh);
$this->first_run = false;
}
}
DÜZENLEME: debug_backtrace() iyi çalışıyor !!!
public function debug($message) {
if(DEBUG) {
$debug_arr = debug_backtrace();
$this->calling_script = $this->getScriptBaseName();
$this->log_file = LOG_FILE_DIRECTORY."/".$this->calling_script.".log";
$this->fh = fopen($this->log_file, 'a') or die("Can't open log file: ".$this->log_file);
if($this->first_run) {
$this->log_entry = "\n[" . date("Y-m-d H:i:s", mktime()) . "][debug]:\t".$message." [line:".$debug_arr[0]['line']."]\n";
} else {
$this->log_entry = "[" . date("Y-m-d H:i:s", mktime()) . "][debug]:\t".$message." [line:".$debug_arr[0]['line']."]\n";
}
fwrite($this->fh, $this->log_entry);
fclose($this->fh);
$this->first_run = false;
}
}
+1 'debug_backtrace' 'in slooow olduğunu unutmayın, bu nedenle yalnızca hata ayıklama modunda kullanılmalıdır. –