I am writing Logger class in PHP. Is there a way, how to automatically pass line number and script file from call?
Sample:
Logger::Log("message", __LINE__, __FILE__)
I want to pass __LINE__ and __FILE__ automatically, without need of writing it. I have tried to make
public static function Log($msg, $l = __LINE__, $f = __FILE__) { ... }
but this pass line number and file of Log method. Is this even possible in PHP?
You can use debug_backtrace inside of Logger::Log to retrieve a call stack, which includes the file and line number of the code that called Logger::Log. That's a sensible thing to include in loggers in general.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With