1

I'd like to call a log method statically throughout my app:

App::log('Some message');

but then I'd like to create a file pointer only once, so that it's accessible from within that method($file_pointer) each time it's called.

public static function log($message) {
  (...)
  fwrite($file_pointer, $processed_message);
}

Is there a design pattern or any other architectural solution that addresses this problem?

tereško
  • 58,060
  • 25
  • 98
  • 150
Alan
  • 1,322
  • 1
  • 21
  • 36

1 Answers1

1

It's not an architectural solution, but you can use file_put_contents() in your log method to circumvent this:

file_put_contents($pathname, $output, FILE_APPEND);

This will append your message to the log file without the need to communicate a file resource, you only have to specify the pathname.

code-kobold
  • 829
  • 14
  • 18