Using __call() for Automatic Method Logging


I have found that time and time again, having good logging can be one of the most essential tools for developing and/or debugging something. It gives you a better insight into what is actually happening in your program. It lets you keep a history of how your program has been performing. It can give valuable debugging data in live environments where editing the code is generally a bad idea. Because of all of this, I try to log as much as I can.

One of the easiest things to do for logging is to simply log every function and/or method call. I’ll leave the details of creating an actual logging system for another time, but this often means going into each and every one of your method calls and adding something like Debug::log(); at the very least. Obviously, this can get very tedious and makes it very easy to simply forget to add in your logging call.

Read more