mosbth / cimage

Server-side image resizing and cropping on the fly with caching of generated image-files using PHP.
http://cimage.se/
MIT License
267 stars 43 forks source link

Create a debug mode that logs events to a logfile #150

Closed mosbth closed 8 years ago

mosbth commented 8 years ago

To make it easier to see what actually happens when cimage processes a request. Enable a debug mode where one can trace and see what happens.

To ease testing and development.

mosbth commented 8 years ago

Enable or disable in the config file.

/**
 * Change to true to enable debug mode which logs additional information
 * to file. Only use for test and development. You must create the logfile
 * and make it writable by the webserver or log entries will silently fail.
 *
 * CIMAGE_DEBUG will be false by default, if its not defined.
 */
if (!defined("CIMAGE_DEBUG")) {
    //define("CIMAGE_DEBUG", false);
    define("CIMAGE_DEBUG", true);
    define("CIMAGE_DEBUG_FILE", "/tmp/cimage");
}

Default is to be disabled.

mosbth commented 8 years ago

This is only for development.

Enable it and use it like this to trace those events that are supported.

$ touch /tmp/cimage && chmod 777 /tmp/cimage && tail -f /tmp/cimage

A trace can look like this.

0.037844ms:0.812MB:8:CImage 200
0.001356ms:0.286MB:8:img.php fast track cache enabled and used
0.001485ms:0.304MB:8:CFastTrackCache 304
0.000850ms:0.286MB:8:img.php fast track cache enabled and used
0.001036ms:0.304MB:8:CFastTrackCache 304
0.001043ms:0.286MB:8:img.php fast track cache enabled and used
0.001213ms:0.304MB:8:CFastTrackCache 304
0.001318ms:0.243MB:5:imgf 304
0.001264ms:0.243MB:5:imgf 304
0.000655ms:0.243MB:5:imgf 304
0.000534ms:0.243MB:5:imgf 304
0.035917ms:0.586MB:9:CImage 200
0.000517ms:0.243MB:5:imgf 200
0.001186ms:0.243MB:5:imgf 200
0.000790ms:0.243MB:5:imgf 304
0.001833ms:0.336MB:9:CImage 304
0.002051ms:0.333MB:9:CImage 200
0.001475ms:0.293MB:8:img.php fast track cache enabled and used
0.001592ms:0.31MB:8:CFastTrackCache 200

Content is timestamp: memory consumption : number files included : custom message.

A sample usage is here:

            if (CIMAGE_DEBUG) {
                trace(__CLASS__ . " 200");
            }

The function trace() is defined in functions.php.