Reputation: 1322
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?
Upvotes: 1
Views: 106
Reputation: 824
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.
Upvotes: 1