Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Where does logging fit in the model view controller architecture?

I would like to log communications activity and, as part of logging, display communications history in a window on the screen. I don't want the communications modules to know about the screen of course, but any method can write to the log. The logging module then routes the information as appropriate (screen, file). Is logging considered part of the model?

like image 289
Bruce Avatar asked Jun 14 '13 13:06

Bruce


1 Answers

Whether the commands, that are executed by instance, are logged or not should not affect the instance itself. Which means that if, for example, you want to log operation performed by controller, the controller itself should not be doing the logging or in any other way be aware that it gets logged.

The much better option is to have the instance decorated. The decorator would require the original instance and a logger injected thought constructor.

Assuming that your MVC components (views, controller and structures from mode layer) are already created via factory, this would be the best "level" at which you switch between logged and unlogged mode.

TL;DR

No. Logging is not part of MVC triad itself.

like image 181
tereško Avatar answered Oct 02 '22 23:10

tereško