Esempio n. 1
0
 /**
  * @param  string
  * @param  int
  * @return bool  If the message should be passed on to the next filter or to the log handler.
  * @throws Exception
  */
 public function filter(LogRecord $rec)
 {
     // dont't filter?
     if ($rec->getLevel() < $this->conf['level'] || cdCtx('cli_debug')) {
         return true;
     }
     // get group
     $group = '?';
     if (($id = @posix_getegid()) !== false) {
         if (($id = @posix_getgrgid($id)) !== false) {
             $group = $id['name'];
         }
     }
     // Date & Level
     $msg = 'Time:       ' . $rec->getTimeFormat() . "\n" . 'Group:User: '******':' . cdUser() . "\n" . 'CWD:        ' . getcwd() . "\n" . 'Level:      ' . $rec->getLevelName() . "\n";
     // Prefix
     $prefix = $rec->getPrefix();
     if ($prefix) {
         $msg .= "Log Prefix: {$prefix}\n";
     } else {
         $prefix = 'main';
     }
     $msg .= "\n";
     // Message
     if ($rec->getThrown()) {
         $msg .= ABException::format($rec->getThrown(), true, false);
     }
     if ($rec->getMessage()) {
         $msg .= $rec->getMessage();
     }
     // Email headers
     $headers = 'From: ' . $this->conf['from'] . "\r\nX-Mailer: contentd/" . cdVersion();
     // Subject
     // %e = exception name, %l = log level, %j = job name
     $logLevelName = ucfirst(trim(strtolower($rec->getLevelName())));
     $subject = strtr($this->conf['subject'], array('%e' => $rec->getThrown() ? get_class($rec->getThrown()) : $logLevelName, '%l' => $logLevelName, '%j' => $prefix));
     // Action
     if (!mail($this->conf['to'], $subject, $msg, $headers)) {
         $rec->setMessage($rec->getMessage() . '. Additionaly, the Mail log filter failed to mail "' . $this->conf['to'] . '"');
     }
     return true;
 }
Esempio n. 2
0
 /**
  * @param  LogRecord
  * @return bool  If false, the filter chain will break
  * @throws Exception
  */
 public function filter(LogRecord $rec)
 {
     // dont't filter?
     if ($rec->getLevel() < $this->parameters['level'] || cdCtx('cli_debug')) {
         return true;
     }
     // Message
     $msg = '';
     if ($rec->getMessage()) {
         $msg .= $rec->getMessage() . "\n";
     }
     if ($rec->getThrown()) {
         $msg .= ABException::format($rec->getThrown(), true, false);
     }
     $msg = trim($msg);
     // forward
     $this->insertRecord($rec, $msg);
     return true;
 }
Esempio n. 3
0
 /**
  * Get log filter configuration by classname
  * 
  * @param  string
  * @return array
  */
 public static function getFilterConfigForClass($classname)
 {
     foreach (cdCtx('log.filters') as $id => $cfg) {
         if ($cfg['class'] == $classname) {
             return $cfg;
         }
     }
 }
Esempio n. 4
0
 /**
  * Rotate
  */
 private function rotate()
 {
     $limit = intval(cdCtx('log.rotate.limit', 0));
     if ($limit < 1) {
         return;
     }
     if (!file_exists($this->file)) {
         return;
     }
     if (filesize($this->file) < $limit) {
         return;
     }
     $pat = cdCtx('log.rotate.datepattern', 'ymd');
     $nameDate = $this->file . '.' . date($pat);
     $saveAs = $nameDate;
     $i = 1;
     while (file_exists($saveAs)) {
         $saveAs = $nameDate . '.' . $i++;
     }
     CDUtils::mv($this->file, $saveAs);
 }