public function SendEmail($subject, $content, $to = array(), $cc = array(), $bcc = array(), $attachments = array()) { $mail = new mailer\PHPMailer(); $mail->IsSMTP(); $mail->CharSet = 'UTF-8'; $mail->Encoding = 'base64'; $mail->SMTPAuth = TRUE; $mail->Host = self::$_config['smtp_host']; $mail->Port = self::$_config['smtp_port']; $mail->Username = self::$_config['smtp_user']; $mail->Password = self::$_config['smtp_pwd']; $mail->SetFrom(self::$_config['mail_from'], "=?UTF-8?B?" . base64_encode(self::$_config['mail_from']) . "?="); $mail->Subject = "=?UTF-8?B?" . base64_encode(self::$_config['subject_pre'] . '-' . $subject) . "?="; $mail->MsgHTML($content); $mail->IsHTML(TRUE); if (count($attachments) > 0) { foreach ($attachments as $attachment) { $mail->AddAttachment($attachment); } } $to = array_merge(self::$_config['mail_to'], $to); $cc = array_merge(self::$_config['mail_cc'], $cc); $bcc = array_merge(self::$_config['mail_bcc'], $bcc); if (count($to) > 0) { foreach ($to as $address) { if (!empty($address)) { $mail->AddAddress($address); } } } if (count($cc) > 0) { foreach ($cc as $address) { if (!empty($address)) { $mail->AddCC($address); } } } if (count($bcc) > 0) { foreach ($bcc as $address) { if (!empty($address)) { $mail->AddBCC($address); } } } $sendResult = $mail->Send(); if (!$sendResult) { Seaslog::error('报警邮件发送失败。{errorInfo}', array('{errirInfo}' => $mail->ErrorInfo), 'alarmer'); } return $sendResult; }
<?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));
public function write($log, $level = "debug") { \Seaslog::debug($log); }
/** * @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; }