3 ms·
The OP doesn't include the implementation of "createLogMessage" because he is suggesting that this method would be part of a framework, and by using it you can
by jakejake 15y ago
The OP doesn't include the implementation of "createLogMessage" because he is suggesting that this method would be part of a framework, and by using it you can focus your mind on your application code, rather than boring details like checking for file locks on a log file.
I do think that choosing where to abstract and where to split functionality is the "art" of the code and we obsess about as we master the craft. So I can appreciate your code example!
I personally like to have a dedicated log function. That way you can refactor from using a file to perhaps a database table or any other method of logging. I personally expose our error logs as RSS and subscribe to the feed - I find it a really easy way to monitor because I'm too lazy to go looking at error log files every day!
- lux 15y agoI was assuming the log() method was also part of the framework, and that this was just a framework-level excerpt... ;) Perhaps such a core Log class could use a separate createLogMessage() method (or formatMessage() as I'd probably name it) that could be overridden in a subclass more easily than overriding the entire log() method. I definitely agree that the API design and finding that balance is a big part of what makes coding an artform!