<?php if (! defined ( 'BASEPATH' ))	exit ( 'No direct script access allowed' );

//require_once '../system/core/Log.php';


/**
 * MY_Log Class
 *
 * This library extends the native Log library.
 * It adds the function to have the log messages being emailed when they have
 * been outputted to the log file.
 *
 * @package     CodeIgniter
 * @subpackage  Libraries
 * @category    Logging
 * @author      Johan Steen
 * @link        https://code.bitbebop.com/
 */
class MY_Log extends CI_Log {
    /**
     * Constructor
     *
     * @access  public
     */
    function __construct()
    {
        
        //echo('aqui');
        
        parent::__construct();
    }

    /**
     * Write Log File
     *
     * Calls the native write_log() method and then sends an email if a log
     * message was generated.
     *
     * @access  public
     * @param   string  the error level
     * @param   string  the error message
     * @param   bool    whether the error is a native PHP error
     * @return  bool
     */
     
    //function write_log($level = 'error', $msg, $php_error = FALSE)
    public function write_log($level, $msg)
    {
        echo($level);
        
        dd($result,$msg);
        
        $result = parent::write_log($level, $msg);

        
        if ($result == TRUE && strtoupper($level) == 'ERROR') {
            
            
            $msg = "An error occurred: \n\n";
            $msg .= $level.' - '.date($this->_date_fmt). ' --> '.$msg."\n";

            $to = 'filipe@viewbrasil.com.br';
            $titulo = 'An error has occured';
            $headers = 'From: Example Name <no-reply@comdono.com>' . "\r\n";
            $headers .= 'Content-type: text/plain; charset=utf-8\r\n';

            
            HEmail::alerta($titulo, $msg);

            //mail($to, $subject, $message, $headers);
        }
        return $result;
    }
}