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: 15-10-17 下午4:12 */ var_dump(SEASLOG_DETAIL_ORDER_ASC); var_dump(SEASLOG_DETAIL_ORDER_DESC); var_dump(SeasLog::getBasePath()); var_dump(SeasLog::getLastLogger()); SeasLog::debug('debug test'); SeasLog::error('错误{aaa}', array('{aaa}' => 'bbb')); SeasLog::error('错误{aaa}', array('{aaa}' => 'ccc'), 'cc'); SeasLog::log('error', '错误{aaa}', array('{aaa}' => 'ddd')); SeasLog::log('asdf', '错误{aaa}', array()); //Seaslog::debug("test"); var_dump(SeasLog::analyzerCount()); var_dump(Seaslog::analyzerDetail("all", "*", NULL, 1, 10, SEASLOG_DETAIL_ORDER_DESC)); var_dump(SeasLog::analyzerCount(SEASLOG_ALL)); var_dump(Seaslog::analyzerDetail(SEASLOG_ERROR, "*", NULL, 1, 1000, SEASLOG_DETAIL_ORDER_DESC)); var_dump(SeasLog::analyzerCount(SEASLOG_DEBUG)); var_dump(Seaslog::analyzerDetail(SEASLOG_DEBUG));
<?php /** * @author neeke@php.net */ ini_set('seaslog.disting_type', 1); $countResult = SeasLog::analyzerCount(); ini_set('seaslog.disting_type', 1); SeasLog::setBasePath(realpath('.')); SeasLog::setLogger('log'); SeasLog::info('log info test'); print_r($countResult);
<?php // $basepath1 = SeasLog::getBasePath(); // SeasLog::setBasePath('/Log/base_test'); // $basepath2 = SeasLog::getBasePath(); // var_dump($basepath1,$basepath2); // echo '<br/>'; // $lastLogger_1 = SeasLog::getLastLogger(); // var_dump($lastLogger_1); SeasLog::log(SEASLOG_ERROR, 'this is a error test by ::log'); SeasLog::info('this is a info log'); //SeasLog::warning('your {website} was down,please {action} it ASAP!',array('{website}' => 'github.com','{action}' => 'rboot')); SeasLog::error('a error log'); echo '<br/>'; $countResult_1 = SeasLog::analyzerCount(); $countResult_2 = SeasLog::analyzerCount(SEASLOG_WARNING); $countResult_3 = SeasLog::analyzerCount(SEASLOG_ERROR, date('Ymd', time())); //,$countResult_2,$countResult_3 print_r($countResult_1); echo '<br/>'; print_r($countResult_2); echo '<br/>'; print_r($countResult_3);
<?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; }