Welcome Guest, Not a member yet? Register   Sign In
Thuỷ Thủ Agency – Công ty thiết kế website chuyên nghiệp tại TP.HCM
#2

(This post was last modified: 03-28-2019, 03:51 AM by InsiteFX.)

Not sure if this is what your looking for, had to re-write it for CI 3.1.10.

It allows you to write to the log file with errors and then email it to you.

PHP Code:
<?php
defined
('BASEPATH') OR exit('No direct script access allowed');

/**
 * -----------------------------------------------------------------------
 * Editor   : PhpStorm
 * Date     : 3/28/2019
 * Time     : 6:22 AM
 * Authors  : Raymond L King Sr.
 * -----------------------------------------------------------------------
 *
 * Class        MY_Log
 *
 * @project     ci3testing
 * @author      Raymond L King Sr.
 * @link        http://www.procoversfx.com
 * @copyright   Copyright (c) 2009 - 2019 Custom Software Designers, LLC.
 * @license     http://www.procoversfx.com/license
 * -----------------------------------------------------------------------
 */

/**
 * Class MY_Log
 *
 * Place into: ./application/core/MY_Log.php
 */
class MY_Log extends CI_Log
{
    
/**
     * Class properties go here.
     * -------------------------------------------------------------------
     * public, private, protected, static and const.
     */

    // -------------------------------------------------------------------

    /**
     * __construct ()
     * -------------------------------------------------------------------
     *
     * Class    Constructor
     *
     * NOTE: Not needed if not setting values or extending a Class.
     *
     */
    
public function __construct()
    {
        
parent::__construct();

        
log_message('debug'"MY_Log Class Initialized");
    }

    
// -------------------------------------------------------------------

    /**
     * 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 '')
    {
        
$result parent::write_log($level$msg);

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

            
$to       '[email protected]';
            
$subject  'An error has occurred';

            
$headers  'From: Example Name <[email protected]>' "\r\n";
            
$headers .= 'Content-type: text/plain; charset=utf-8\r\n';

            
mail($to$subject$message$headers);
        }

        return 
$result;
    }

    
// -------------------------------------------------------------------

  // End of MY_Log Library Class.


/**
 * -----------------------------------------------------------------------
 * Filename: MY_Log.php
 * Location: ./application/libraries/MY_Log.php
 * -----------------------------------------------------------------------
 */ 
What did you Try? What did you Get? What did you Expect?

Joined CodeIgniter Community 2009.  ( Skype: insitfx )
Reply


Messages In This Thread
RE: hELP ME! Reporting sending to email ERROR - by InsiteFX - 03-28-2019, 03:34 AM



Theme © iAndrew 2016 - Forum software by © MyBB