/**
  * Logs an error to the database.
  *
  * @access  public
  * @param   string    $message        The log entry message.
  * @param   int       $severity       The log entry 'level.'
  * @param   array     $emails         Array of 'admin' emails.
  * @param   string    $extended_data  Additional data.
  * @return  void
  */
 public function log_error($message, $severity = 1, array $emails = array(), $extended_data = '')
 {
     if (class_exists('Omnilog_entry') && class_exists('Omnilogger')) {
         switch ($severity) {
             case 3:
                 $notify = TRUE;
                 $type = Omnilog_entry::ERROR;
                 break;
             case 2:
                 $notify = FALSE;
                 $type = Omnilog_entry::WARNING;
                 break;
             case 1:
             default:
                 $notify = FALSE;
                 $type = Omnilog_entry::NOTICE;
                 break;
         }
         $omnilog_entry = new Omnilog_entry(array('addon_name' => 'MailChimp Subscribe', 'admin_emails' => $emails, 'date' => time(), 'extended_data' => $extended_data, 'message' => $message, 'notify_admin' => $notify, 'type' => $type));
         Omnilogger::log($omnilog_entry);
     }
 }
Пример #2
0
 /**
  * Runs a demo.
  *
  * @access  public
  * @return  void
  */
 public function run_demo()
 {
     $redirect_url = $this->_base_url . AMP . 'method=demo';
     if (!file_exists(PATH_THIRD . 'omnilog/classes/omnilogger' . EXT)) {
         $this->EE->session->set_flashdata('message_failure', $this->EE->lang->line('demo_flashdata_missing_omnilogger'));
         $this->EE->functions->redirect($redirect_url);
     }
     include_once PATH_THIRD . 'omnilog/classes/omnilogger' . EXT;
     $this->EE->load->helper('email');
     $demo = $this->EE->input->get('demo');
     $emails = array();
     switch ($demo) {
         case 'log_error':
             $notify = FALSE;
             $type = Omnilog_entry::ERROR;
             break;
         case 'log_notice':
             $notify = FALSE;
             $type = Omnilog_entry::NOTICE;
             break;
         case 'log_warning':
             $notify = FALSE;
             $type = Omnilog_entry::WARNING;
             break;
         case 'notify_standard':
             $emails = array($this->EE->config->item('webmaster_email'));
             $notify = TRUE;
             $type = Omnilog_entry::ERROR;
             break;
         case 'notify_custom':
             $emails = array();
             $raw_emails = explode(',', urldecode($this->EE->input->get('email')));
             foreach ($raw_emails as $email) {
                 $emails[] = trim($email);
             }
             $notify = TRUE;
             $type = Omnilog_entry::ERROR;
             break;
         default:
             $notify = FALSE;
             $type = FALSE;
             break;
     }
     if (!$type) {
         $this->EE->session->set_flashdata('message_failure', $this->EE->lang->line('demo_flashdata_unknown_demo'));
         $this->EE->functions->redirect($redirect_url);
     }
     $omnilog_entry = new Omnilog_entry(array('addon_name' => 'OmniLog Demo', 'admin_emails' => $emails, 'date' => time(), 'message' => $this->EE->lang->line('demo_message'), 'extended_data' => $this->EE->lang->line('demo_extended_data'), 'notify_admin' => $notify, 'type' => $type));
     if (!Omnilogger::log($omnilog_entry)) {
         $this->EE->session->set_flashdata('message_failure', $this->EE->lang->line('demo_flashdata_failure'));
     } else {
         $this->EE->session->set_flashdata('message_success', $this->EE->lang->line('demo_flashdata_success'));
     }
     $this->EE->functions->redirect($redirect_url);
 }
 private function _log_core($msg, $extended = '', $severity = 1, $emails = array())
 {
     if (class_exists('Omnilog_entry') && class_exists('Omnilogger')) {
         switch ($severity) {
             case 3:
                 $notify = TRUE;
                 $type = Omnilog_entry::ERROR;
                 break;
             case 2:
                 $notify = FALSE;
                 $type = Omnilog_entry::WARNING;
                 break;
             case 1:
             default:
                 $notify = FALSE;
                 $type = Omnilog_entry::NOTICE;
                 break;
         }
         // Once we hit $max_logs it's a strict one-in, one-out policy
         $this->EE->db->from('omnilog_entries');
         $this->EE->db->where('addon_name', $this->name);
         if ($this->EE->db->count_all_results() >= $this->max_logs) {
             $this->EE->db->where('addon_name', $this->name);
             $this->EE->db->order_by('log_entry_id', 'desc');
             $query = $this->EE->db->get('omnilog_entries', 1, $this->max_logs - 1);
             if ($query->row('log_entry_id')) {
                 $this->EE->db->where('log_entry_id <=', $query->row('log_entry_id'));
                 $this->EE->db->where('addon_name', $this->name);
                 $this->EE->db->delete('omnilog_entries');
             }
         }
         $omnilog_entry = new Omnilog_entry(array('addon_name' => $this->name, 'admin_emails' => $emails, 'date' => time(), 'extended_data' => $extended, 'message' => $msg, 'notify_admin' => $notify, 'type' => $type));
         Omnilogger::log($omnilog_entry);
     }
 }
 public function test__log__notify_admin_failure()
 {
     $exception_message = 'Exception';
     $log_entry = new Omnilog_entry($this->_log_entry_props);
     $log_entry->set_notify_admin(TRUE);
     $saved_entry_props = array_merge($log_entry->to_array(), array('log_entry_id' => 10));
     $saved_entry = new Omnilog_entry($saved_entry_props);
     // $this->_model->expectOnce('save_entry_to_log', array($log_entry));
     $this->_model->expectOnce('save_entry_to_log', array('*'));
     $this->_model->setReturnValue('save_entry_to_log', $saved_entry);
     // $this->_model->expectOnce('notify_site_admin_of_log_entry',
     //  array($saved_entry));
     $this->_model->expectOnce('notify_site_admin_of_log_entry', array('*'));
     $this->_model->throwOn('notify_site_admin_of_log_entry', new Exception($exception_message));
     $this->assertIdentical(FALSE, Omnilogger::log($log_entry));
 }