3

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?

1 Answer 1

7

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.