public static function analyzerRun($configKey = NULL, $config = array()) { if (empty($configKey) || !is_array($config) || count($config) < 1) { throw new \Exception('$configKey can`t be empty || $config must be an array.'); } \SeasLog::setLogger($config['module']); $logLevel = intval($config['level']); if (empty($logLevel)) { $logLevel = SEASLOG_ERROR; } $_analyzer_count = \SeasLog::analyzerCount($logLevel); $_count_bar = array_key_exists('bar', $config) ? intval($config['bar']) : 1; if ($_analyzer_count > 0 && $_analyzer_count >= $_count_bar) { $to = array_key_exists('mail_to', $config) ? explode(',', $config['mail_to']) : array(); $cc = array_key_exists('mail_cc', $config) ? explode(',', $config['mail_cc']) : array(); $bcc = array_key_exists('mail_bcc', $config) ? explode(',', $config['mail_bcc']) : array(); $subject = ' report - ' . $configKey . ' - ' . date('Y-m-d H:i:s', time()); $_title = $config['module'] . ' 检测到 ' . $_analyzer_count . "个问题\n\n"; $_detail = \SeasLog::analyzerDetail($logLevel); $_detail = '以下是此次检测详情<br /><br />' . implode("<br />", $_detail); $content = mailTpl::processMail($_title, $_detail, 'processed time ' . date('Y-m-d H:i:s', time())); alarmer::instanse()->SendEmail($subject, $content, $to, $cc, $bcc); } }
<?php /** * @author ciogao@gmail.com * Date: 14-1-27 下午4:41 */ SeasLog::getBasePath(); SeasLog::setBasePath('/log/test/base/path'); SeasLog::setLogger('test/logger'); SeasLog::log(SEASLOG_ERROR, 'this is a error test by ::log'); SeasLog::debug('this is a {userName} debug', array('{userName}' => 'neeke')); SeasLog::info('this is a info log'); SeasLog::notice('this is a notice log'); SeasLog::warning('your {website} was down,please {action} it ASAP!', array('{website}' => 'github.com', '{action}' => 'rboot')); SeasLog::error('a error log'); SeasLog::critical('some thing was critical'); SeasLog::alert('yes this is a {messageName}', array('{messageName}' => 'alertMSG')); SeasLog::emergency('Just now, the house next door was completely burnt out! {note}', array('{note}' => 'it`s a joke')); var_dump(SeasLog::analyzerCount()); var_dump(SeasLog::analyzerDetail(SEASLOG_INFO, date('Ymd', time()))); var_dump(SeasLog::getLastLogger()); $buffer = SeasLog::getBuffer(); var_dump($buffer); die;
<?php /** * @author ciogao@gmail.com * Date: 14-1-27 下午4:41 */ SeasLog::getBasePath(); SeasLog::setBasePath('/log/test/base/path'); SeasLog::setLogger('test/logger'); SeasLog::log(SEASLOG_ERROR, 'this is a error test by ::log'); SeasLog::debug('this is a {userName} debug', array('{userName}' => 'neeke')); SeasLog::info('this is a info log'); SeasLog::notice('this is a notice log'); SeasLog::warning('your {website} was down,please {action} it ASAP!', array('{website}' => 'github.com', '{action}' => 'rboot')); SeasLog::error('a error log'); SeasLog::critical('some thing was critical'); SeasLog::alert('yes this is a {messageName}', array('{messageName}' => 'alertMSG')); SeasLog::emergency('Just now, the house next door was completely burnt out! {note}', array('{note}' => 'it`s a joke')); var_dump(SeasLog::analyzerCount()); var_dump(SeasLog::analyzerDetail(SEASLOG_INFO, date('Ymd', time()))); var_dump(SeasLog::analyzerDetail(SEASLOG_DEBUG, date('Ymd', time()), 'neeke', 1, 40)); var_dump(SeasLog::getLastLogger()); $buffer = SeasLog::getBuffer(); var_dump($buffer);
/** * @param int $page * @param null $iLogType * @param null $time * @param null $level * @param null $key_word * * @return array */ public function getLog($page = 0, $iLogType = NULL, $time = NULL, $level = NULL, $key_word = NULL) { $return = array('page' => array(), 'data' => array()); \Seaslog::setLogger($iLogType); $date = date('Ymd', time()); if ($time) { $time = substr($time, 0, 8); $date = $time; } $data = array(); $page_info = array(); if ($level === NULL) { $logList = \SeasLog::analyzerDetail($level, $date, $key_word, 1, 50); } else { $rowCount = \SeasLog::analyzerCount($level, $date, $key_word); $page_info['max_page'] = ceil($rowCount / self::PAGE_LIMIT); if ($page > $page_info['max_page']) { $page = $page_info['max_page']; } if ($page < 1) { $page = 1; } if ($page_info['max_page'] <= 9) { $return['jump'] = array('min' => 1, 'max' => $page_info['max_page']); } elseif ($page > 5 && $page < $page_info['max_page'] - 5) { $return['jump'] = array('min' => $page - 4, 'max' => $page + 4); } elseif ($page < 5) { $return['jump'] = array('min' => 1, 'max' => 9); } else { $return['jump'] = array('min' => $page_info['max_page'] - 8, 'max' => $page_info['max_page']); } $page_info['current_page'] = $page; $start = $rowCount - self::PAGE_LIMIT * $page + 1; $end = $rowCount - self::PAGE_LIMIT * $page + self::PAGE_LIMIT; if ($start < 0) { $end = $rowCount - self::PAGE_LIMIT * $page + self::PAGE_LIMIT; $start = 1; } $logList = \SeasLog::analyzerDetail($level, $date, $key_word, $start, $end); } $i = 0; if (count($logList)) { foreach ($logList as $info) { if ($info == '::::::::::::::') { continue; } $tmp = explode('|', $info); if (count($tmp) != 5) { if (!count($data)) { continue; } else { $data[$i - 1]['detail'] .= $info; continue; } } $data[$i]['level'] = trim($tmp['0']); $data[$i]['pid'] = trim($tmp['1']); $time = trim($tmp['3']); $data[$i]['time'] = $time; $data[$i]['detail'] = trim($tmp['4']); $i++; } krsort($data); $return['data'] = $data; } $return['page'] = $page_info; return $return; }