SoccerGloves Posted December 30, 2009 Share Posted December 30, 2009 Hello, I have a question about my messaging / error logging system. I am working on a data-crunching script, so it doesn't get viewed as a public web page, it only is seen by the administrator. All it needs is a simple on-screen output tape that keeps the person who is running it up to date on how it is working. So, lots of non-error status messages get written to the screen, and also into a log file and a log database-table. I'd like to make a clean, standard way for handling all these messages. I considered making my own "message" object that would contain a text message describing the error, an "importance" code, a message type ("error", "info", or "debug"), and a debug trace. So here's my question: the built in Exception class has almost all that stuff already, and I could extend it. Could I use exceptions for non-error messages? Would that be good practice? It would look like this: $m = new ExeptionMessage('normal operation...50% done', 2, 'info'); $myMessageLoggingObject->send($m); this would be slick: I wouldn't need to make my own message object, and I could swap-in normal, ordinary, thrown exceptions into my ->send() function, and they would work just fine! catch (Exception $e) { $myMessageLoggingObject->send($e); } Is there any problems you could see with this? Is it bad practice to use Exceptions when they are not being thrown? Thanks! Link to comment https://forums.phpfreaks.com/topic/186709-message-system/ Share on other sites More sharing options...
SoccerGloves Posted January 10, 2010 Author Share Posted January 10, 2010 If this is a completely off-base idea, what is a more normal way to do this? Just make your own message class? Link to comment https://forums.phpfreaks.com/topic/186709-message-system/#findComment-992370 Share on other sites More sharing options...
ignace Posted January 11, 2010 Share Posted January 11, 2010 take a look at Zend_Log they even allow you to create your own error codes http://framework.zend.com/manual/en/zend.log.html Link to comment https://forums.phpfreaks.com/topic/186709-message-system/#findComment-992945 Share on other sites More sharing options...
SoccerGloves Posted January 12, 2010 Author Share Posted January 12, 2010 Thanks! I think I'll go in that type of direction. Link to comment https://forums.phpfreaks.com/topic/186709-message-system/#findComment-993598 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.