/** * This returns/prints a critical message regarding the active script. Intended to be used by the developer. * * @version 1.1 * @date 20120308 (v1.1) (greg) switched to notifications queue * * @param string This is the message that will be displayed. * @param mixed default is print, can be set true, print, return. * @param mixed default is log, can be set true, print, return. * @return string Critical string. * @author Jason Schoeman */ public function critical($critical, $return = 'print', $log = 'log', $mail = 'mailadmin') { $navigation = $this->navigation->navigation; if ($log === true || $log == 'log') { // Log types are : //////////////// // 1 = OK ///////////////////////// // 2 = Warning //////////////////// // 3 = Critical /////////////////// // 4 = Log-in ///////////////////// // 5 = Log-out //////////////////// /////////////////////////////////// $log_type = 3; //////////////////// // Log the event ////////////////// $this->db->logArray[] = array('log_type' => $log_type, 'log_description' => $critical); } // Check if we need to email admin. if ($this->configuration['email_critical']) { // Subject. $subject = sprintf(___("CRITICAL ERROR NOTIFICATION %s"), $this->configuration['scripts_name_version']); // Message. $broke_script = $navigation[$this->configuration['m']]['menu_name']; $broken_url = $this->configuration['absolute_url'] . '/index.php?m=' . $this->configuration['m']; $message = sprintf(___("Admin,")) . "\r\n\r\n"; $message .= sprintf(___("THERE WAS A CRITICAL ERROR IN %s:"), $this->configuration['scripts_name_version']) . "\r\n\r\n" . $critical . "\r\n\r\n"; $message .= sprintf(___("Click on url to access broken script called %s:"), $broke_script) . "\r\n" . $broken_url . "\r\n"; $message .= sprintf(___("Script error occurred for user : %s"), $this->configuration['user_display_name']); if ($mail === true || $mail == 'mailadmin') { // Initiate email class. $email = $this->factory('mailer'); // Ok we can now send the critical email message. $email->sendmail("{$this->configuration['setting_admin_email']}", $subject, $message); } } // Create HTML. $html = $this->mod->critical($critical); // Return or print to browser. if ($return === 'print' || $return == false) { $this->notif->add(array('critical', $html)); } else { if ($return === 'return' || $return == true) { return $html; } } }
/** * PSR-3 Logs with an arbitrary level. * * @param mixed $level logging level * @param string $message message * @param array $context array of additional context * * @return null */ public function log($level, $message, array $context = array()) { if (!$this->activated) { return; } $channel = 'messages'; $msg = $message; /** * If we have embedded channel in the context array, format the message * approriatly using context values. */ if (isset($context['channel'])) { $chan = strtolower($context['channel']); switch ($chan) { case 'blocks': if (!$this->configs['include_blocks']) { return; } //$channel = 'Blocks'; $msg = _MD_MONOLOG_BLOCKS . ' : ' . $message . ': '; if ($context['cached']) { $msg .= sprintf(_MD_MONOLOG_CACHED, (int) $context['cachetime']); } else { $msg .= _MD_MONOLOG_NOT_CACHED; } break; case 'deprecated': if (!$this->configs['include_deprecated']) { return; } //$channel = 'Deprecated'; $msg = $this->messageTag('_MD_MONOLOG_DEPRECATED', 'Deprecated*') . ' : ' . $message; //$msg = _MD_MONOLOG_DEPRECATED . ' : ' . $message; break; case 'extra': if (!$this->configs['include_extra']) { return; } //$channel = 'Extra'; $msg = _MD_MONOLOG_EXTRA . ' : ' . $context['name'] . ': ' . $message; break; case 'queries': if (!$this->configs['include_queries']) { return; } //$channel = 'Queries'; $msg = $message; $qt = empty($context['query_time']) ? '' : sprintf('%0.6f - ', $context['query_time']); if ($level == LogLevel::ERROR) { //if (!is_scalar($context['errno']) || !is_scalar($context['errno'])) { // \Xmf\Debug::dump($context); //} $msg .= ' -- Error number: ' . (is_scalar($context['errno']) ? $context['errno'] : '?') . ' Error message: ' . (is_scalar($context['error']) ? $context['error'] : '?'); } $msg = $this->messageTag('_MD_MONOLOG_QUERIES', 'Queries*') . ' : ' . $qt . $msg; break; case 'timers': if (!$this->configs['include_timers']) { return; } $msg = $this->messageTag('_MD_MONOLOG_TIMERS', 'Timers*') . ' : ' . $message; break; default: $msg = $this->messageTag('_MD_MONOLOG_ERRORS', 'Errors*') . ' : ' . $message; break; } } else { $msg = $this->messageTag('_MD_MONOLOG_MESSAGES', 'Message*') . ' : ' . $message; } switch ($level) { case LogLevel::EMERGENCY: $this->monolog->emergency($msg, $context); break; case LogLevel::ALERT: $this->monolog->alert($msg, $context); break; case LogLevel::CRITICAL: $this->monolog->critical($msg, $context); break; case LogLevel::ERROR: $this->monolog->error($msg, $context); break; case LogLevel::WARNING: $this->monolog->warning($msg, $context); break; case LogLevel::NOTICE: $this->monolog->notice($msg, $context); break; case LogLevel::INFO: $this->monolog->info($msg, $context); break; case LogLevel::DEBUG: default: $this->monolog->debug($msg, $context); break; } }