<?php
/**
 *  (c) CloudMunch Inc.
 *  All Rights Reserved
 *  Un-authorized copying of this file, via any medium is strictly prohibited
 *  Proprietary and confidential
 *
 *  Rosmi Chandy rosmi@cloudmunch.com
 */
/**
 * This file handles error/debug logs
 * @author Rosmi
 */
/**
 * 
 * Log level : debug
 */
const DEBUG = 'DEBUG';

/**
 * 
 * Log level : info
 */
const INFO = 'INFO';

/**
 * Error handling method.
 * @param string $errno
 * @param string $errstr
 * @param string $errfile
 * @param string $errline
 * @return void|boolean
 */

function myErrorHandler($errno, $errstr, $errfile, $errline) {
    if (!(error_reporting() & $errno)) {
        // This error code is not included in error_reporting
        return;
    }

    date_default_timezone_set('UTC');
    $date =date('Y-m-d H:i:s');
    switch ($errno) {
        case E_RECOVERABLE_ERROR :
        case E_COMPILE_ERROR :
        case E_CORE_ERROR :
        case E_PARSE :
        case E_ERROR :
        case E_USER_ERROR :
            echo "<b><font color=\"red\">ERROR</b> [$date] $errstr\n";
            echo "\nAborting...</font><br />\n";
            exit (1);
            break;
        case E_CORE_WARNING :

        case E_WARNING :
        case E_USER_WARNING :
            if (strpos($errstr, 'ssh2_connect():') !== false) {
                $msg = "Could not connect to the server";
                echo "<b>INFO</b> [$date] $msg\n";
            } else {
                echo "<b>WARNING</b> [$date] $errstr\n";
            }
            break;
        case E_STRICT :
        case E_NOTICE :
        case E_USER_NOTICE :
             break;

        default :
            echo "Unknown error type: [$date] $errstr\n";
            break;
    }

    /* Don't execute PHP internal error handler */
    return true;
}

set_error_handler("myErrorHandler");
date_default_timezone_set('UTC');


?>

