see https://github.com/stevethomas/codeigniter-monolog & https://github.com/Seldaek/monolog
 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);
 }
Beispiel #2
0
 public function __construct()
 {
     parent::__construct();
     $config =& get_config();
     $this->_levels = $config['log_levels'];
     $this->_template = $config['log_template'];
     $this->_ip = $this->_getIp();
     $this->_logId = intval(microtime(true) * 1000000) + mt_rand(0, 999);
 }
 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;
 }
Beispiel #5
0
 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);
     }
 }
Beispiel #6
0
 /**
  * Constructor
  *
  * @access    public
  * @param    array the array of loggable items
  * @param    string    the log file path
  * @param     string     the error threshold
  * @param    string    the date formatting codes
  */
 function MY_Log()
 {
     parent::CI_Log();
     $config =& get_config();
     if (isset($config['show_in_log'])) {
         $show_in_log = $config['show_in_log'];
     } else {
         $show_in_log = "";
     }
     $this->log_path = $config['log_path'] != '' ? $config['log_path'] : BASEPATH . 'logs/';
     if (!is_dir($this->log_path) or !is_really_writable($this->log_path)) {
         $this->_enabled = FALSE;
     }
     if (is_array($show_in_log)) {
         $this->_logging_array = $show_in_log;
     }
     if (is_numeric($config['log_threshold'])) {
         $this->_threshold = $config['log_threshold'];
     }
     if ($config['log_date_format'] != '') {
         $this->_date_fmt = $config['log_date_format'];
     }
 }
Beispiel #7
0
 /**
  * Constructor
  */
 public function __construct()
 {
     parent::__construct();
     $config =& get_config();
     if (isset($config['mylog_cats'])) {
         $mylog_cats = $config['mylog_cats'];
     } else {
         $mylog_cats = "";
     }
     $this->_enable_sub_directory = isset($config['mylog_sub_directories']) ? $config['mylog_sub_directories'] : false;
     $this->log_path = $config['log_path'] != '' ? $config['log_path'] : APPPATH . 'logs/';
     if (!is_dir($this->log_path) or !is_really_writable($this->log_path)) {
         $this->_enabled = FALSE;
     }
     if (is_array($mylog_cats)) {
         $this->_logging_array = $mylog_cats;
     }
     if (is_numeric($config['log_threshold'])) {
         $this->_threshold = $config['log_threshold'];
     }
     if ($config['log_date_format'] != '') {
         $this->_date_fmt = $config['log_date_format'];
     }
 }
Beispiel #8
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);
 }
Beispiel #9
0
 function __construct()
 {
     parent::__construct();
 }
Beispiel #10
0
 function MY_Log()
 {
     parent::__construct();
 }
Beispiel #11
0
 /**
  * Class constructor
  *
  * @return	void
  */
 public function __construct()
 {
     $config =& get_config();
     isset(self::$func_override) or self::$func_override = extension_loaded('mbstring') && ini_get('mbstring.func_override');
     $this->_log_path = $config['log_path'] !== '' ? $config['log_path'] : APPPATH . 'logs/';
     $this->_file_ext = isset($config['log_file_extension']) && $config['log_file_extension'] !== '' ? ltrim($config['log_file_extension'], '.') : 'php';
     file_exists($this->_log_path) or mkdir($this->_log_path, 0755, TRUE);
     if (!is_dir($this->_log_path) or !is_really_writable($this->_log_path)) {
         $this->_enabled = FALSE;
     }
     if (is_numeric($config['log_threshold'])) {
         $this->_threshold = (int) $config['log_threshold'];
     } elseif (is_array($config['log_threshold'])) {
         $this->_threshold = 0;
         $this->_threshold_array = array_flip($config['log_threshold']);
     }
     if (!empty($config['log_date_format'])) {
         $this->_date_fmt = $config['log_date_format'];
     }
     if (!empty($config['log_file_permissions']) && is_int($config['log_file_permissions'])) {
         $this->_file_permissions = $config['log_file_permissions'];
     }
 }
/**
* 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);
}
	function __construct()
    {
    	$this->mongo = new Mongo("localhost");
        parent::CI_Log();
    }
Beispiel #14
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);
 }