I have a class which logs a record into a file each time one of it's functions its called.
I would like to avoid including the logging code into each function. I don't believe it's a good coding practice.
class Foo {
function foo1() {
file_put_contents("log","Foo1 has been called");
// do something
}
function foo2() {
file_put_contents("log","Foo2 has been called");
// do something
}
function foo3() {
file_put_contents("log","Foo3 has been called";
// do something
}
}
I want to take out the file_put_contents() from each function but still write the log when a function is called!. Is there any design pattern to do that?