write_log() 공개 메소드

Generally this function will be called using the global log_message() function
public write_log ( string $level, string $msg ) : boolean
$level string The error level: 'error', 'debug' or 'info'
$msg string The error message
리턴 boolean
 function write_log($level = 'error', $msg, $php_error = FALSE)
 {
     parent::write_log($level, $msg, $php_error);
     //$memory	 = (!function_exists('memory_get_usage')) ? '0' : memory_get_usage();
     $b = load_class('Benchmark');
     $b->mark($msg);
     $this->logs[] = array(date('Y-m-d H:i:s P'), $level, $msg);
 }
예제 #2
0
 public function create()
 {
     $logger = new CI_Log();
     //$logger::_log_path='E:/Users/cds/Nolwenn/logs/CI/';
     $logger->write_log($level = 'debug', 'create', $php_error = FALSE);
     $this->load->helper('form');
     $this->load->library('form_validation');
     $data['title'] = 'Create a news item';
     $this->form_validation->set_rules('title', 'Title', 'required');
     $this->form_validation->set_rules('text', 'Text', 'required');
     if ($this->form_validation->run() === FALSE) {
         $logger->write_log($level = 'debug', 'validation', $php_error = FALSE);
         $this->load->view('templates/header', $data);
         $this->load->view('news/create');
         $this->load->view('templates/footer');
     } else {
         $logger->write_log($level = 'debug', 'success', $php_error = FALSE);
         $this->news_model->set_news();
         $this->load->view('news/success');
     }
 }
 /**
  * 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)
 {
     $result = parent::write_log($level, $msg, $php_error);
     if ($result == TRUE && strtoupper($level) == 'ERROR' && EMAIL_ERROR_LOG == TRUE) {
         $message = "An error occurred: \n\n";
         $message .= $level . ' - ' . date($this->_date_fmt) . ' --> ' . $msg . "\n";
         $to = DEVELOPER_EMAIL;
         $subject = 'An error has occured on apps';
         $headers = 'From: ' . WEBSITE_NAME . ' system <' . SYSTEM_EMAIL . '>' . "\r\n";
         $headers .= 'Content-type: text/plain; charset=utf-8\\r\\n';
         @mail($to, $subject, $message, $headers);
     }
     return $result;
 }
예제 #4
0
파일: MY_Log.php 프로젝트: sevir/toffy-lite
 function write_log($level = 'error', $msg, $php_error = FALSE)
 {
     if ($this->_enabled === FALSE) {
         return FALSE;
     }
     $level = strtoupper($level);
     if (!isset($this->_levels[$level]) or $this->_levels[$level] > $this->_threshold) {
         return FALSE;
     }
     if ($this->redis_enabled) {
         $this->redis->lpush($this->log_prefix . '-' . date('Y-m-d'), $level . ' - ' . date($this->_date_fmt) . ' --> ' . $msg);
     } else {
         parent::write_log($level, $msg, $php_error);
     }
 }
예제 #5
0
 public function write_log($level = 'error', $msg, $php_error = FALSE)
 {
     //	Ensure this is set correctly. Would use the constructor, however
     //	that is called before the pre_system hook (as the constructor of
     //	the hook class calls log_message() which in turn constructs this class.
     //	The docs LIE when theys ay only benchmark and hooks class are loaded)
     if (defined('DEPLOY_LOG_DIR')) {
         $this->_log_path = DEPLOY_LOG_DIR;
         //	If we haven't already, check to see if DEPLOY_LOG_DIR is writeable
         if (NULL == $this->_enabled) {
             if (is_writeable($this->_log_path)) {
                 //	Writeable!
                 $this->_enabled = TRUE;
             } else {
                 //	Not writeable, disable logging and kick up a fuss
                 $this->_enabled = FALSE;
                 //	Send developer mail, but only once
                 if (!defined('NAILS_LOG_ERROR_REPORTED')) {
                     if (isset($_SERVER['REQUEST_URI'])) {
                         $_uri = $_SERVER['REQUEST_URI'];
                     } else {
                         //	Most likely on the CLI
                         if (isset($_SERVER['argv'])) {
                             $_uri = 'CLI: ' . implode(' ', $_SERVER['argv']);
                         } else {
                             $_uri = 'Unable to determine URI';
                         }
                     }
                     $_message = strtoupper($level) . ' ' . (strtoupper($level) == 'INFO' ? ' -' : '-') . ' ' . date($this->_date_fmt) . ' --> ' . $msg . "\n";
                     $_appname = defined('APP_NAME') ? APP_NAME : '[Could not determine app name]';
                     $_subject = 'Log folders are not writeable on ' . $_appname;
                     $_message = 'I just tried to write to the log folder for ' . $_appname . ' and found them not to be writeable.' . "\n";
                     $_message .= '' . "\n";
                     $_message .= 'Get this fixed ASAP - I\'ll bug you every time this happens.' . "\n";
                     $_message .= '' . "\n";
                     $_message .= 'FYI, the entry was:' . "\n";
                     $_message .= '' . "\n";
                     $_message .= $msg . "\n";
                     $_message .= '' . "\n";
                     $_message .= 'The calling URI was:' . "\n";
                     $_message .= '' . "\n";
                     $_message .= $_uri . "\n";
                     $_message .= '' . "\n";
                     $_message .= 'The path was:' . "\n";
                     $_message .= '' . "\n";
                     $_message .= $this->_log_path . "\n";
                     $_message .= '' . "\n";
                     $_message .= 'PHP SAPI Name:' . "\n";
                     $_message .= '' . "\n";
                     $_message .= php_sapi_name() . "\n";
                     $_message .= '' . "\n";
                     $_message .= 'PHP Debug Backtrace:' . "\n";
                     $_message .= '' . "\n";
                     $_message .= serialize(debug_backtrace()) . "\n";
                     $_from_email = 'root@' . gethostname();
                     $_from_name = defined('APP_EMAIL_FROM_NAME') ? APP_EMAIL_FROM_NAME : 'Log Error Reporter';
                     $_reply_to = defined('APP_EMAIL_FROM_EMAIL') ? APP_EMAIL_FROM_EMAIL : $_from_email;
                     $_to = defined('ENVIRONMENT') && ENVIRONMENT != 'production' && defined('EMAIL_OVERRIDE') && EMAIL_OVERRIDE ? EMAIL_OVERRIDE : APP_DEVELOPER_EMAIL;
                     $_headers = 'From: ' . $_from_name . ' <' . $_from_email . '>' . "\r\n" . 'Reply-To: ' . $_reply_to . "\r\n" . 'X-Mailer: PHP/' . phpversion() . "\r\n" . 'X-Priority: 1 (Highest)' . "\r\n" . 'X-Mailer: X-MSMail-Priority: High/' . "\r\n" . 'Importance: High';
                     @mail($_to, '!! ' . $_subject, $_message, $_headers);
                     define('NAILS_LOG_ERROR_REPORTED', TRUE);
                 }
             }
         }
     } else {
         //	Don't bother writing as we don't know where to write.
         return FALSE;
     }
     // --------------------------------------------------------------------------
     //	Test Log folder, but only if the error level is to be captured
     $level = strtoupper($level);
     if (!isset($this->_levels[$level]) or $this->_levels[$level] > $this->_threshold) {
         return FALSE;
     }
     parent::write_log($level, $msg, $php_error);
 }
/**
* Error Logging Interface 
*
* We use this as a simple mechanism to access the logging
* class and send messages to be logged.
*
* @access	public
* @return	void
*/
function log_message($level = 2, $message, $php_error = FALSE)
{
    global $config;
    if ($config['log_errors'] === FALSE) {
        return;
    }
    if (!class_exists('CI_Log')) {
        include_once BASEPATH . 'libraries/Log.php';
    }
    if (!isset($LOG)) {
        $LOG = new CI_Log($config['log_path'], $config['log_threshold'], $config['log_date_format']);
    }
    $LOG->write_log($level, $message, $php_error);
}
예제 #7
0
 /**
  * Write Log File
  *
  * Generally this function will be called using the global log_message() function
  *
  * @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)
 {
     return parent::write_log($level, '(uniq=' . $this->_uniq . ') ' . $msg, $php_error);
 }