Standardization of non-fatal debug messages.

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

Standardization of non-fatal debug messages.

Kevin McArthur-2
I'm wondering what we're currently planning on doing for non-fatal debugging information. Willie and I are coming across a few problems implementing the font and image processing functions for Zend_Pdf.
 
The scenario is this; some fonts and images can be loaded however, may not work correctly. These items should throw a warning/notice not an exception as the errors are non-fatal/recoverable. Right now we're using Zend_Log in the prototypes to log to a custom log for that component; however, to enable this, you actually have to edit a framework file and its far from a standardized way of doing this.
 
An example is tRNS chunks for indexed color png's. Right now we're just masking the first transparent index color, but it really should be a proper SMask. This should generate a warning/notice and not just silently degrade. We also have some fonts that need cmap corrections in order to render properly, but that can be fixed-on-the-fly and used, though there may be resulting problems further downstream resulting from the use of a bad input font in the first place.
 
So the question comes down to, what is the current standardization plan for debugging messages/levels within framework componentry?
 
I'd think this would probably be best in some type of delegate pattern where the log class wont do anything unless a logger is attached to it. This would allow us to add the calls within the componentry without a lot of extra code, and still let people control where the logs go from their bootstrap file.
 
//Pseudocode for explanation purposes only
class some_singleton_log {
    //singleton pattern
    $listeners = array();
    public function logwhatever($message, $type, $level) {
        //iterate listeners and look for an entry that matches type and is >= level {
            $listener->log($message, $type, $level);
        }
    }
    //addlistener func(listener $listener, $type, $minlevel)
}
 
class listener {
    protected $logfile;
    public function __construct($logfile) {
        $this->logfile = $logfile;
    }
    public function log($message, $type, $level) {
       // fwrite etc to $this->logfile.
    }
}
 
bootstrap..
 
$log = $some_singleton_log::getInstance()
$log->addListener(new listener('/path/to/file'), 'debug', 5);
 
Comments?
 
Kevin McArthur
 

smime.p7s (3K) Download Attachment