Exemplo 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;
 }
Exemplo n.º 2
0
 /**
  * Called upon to store (INSERT) a log record into the database.
  *
  * Normally called upon by the <samp>filter</samp> method after
  * figuring out a record should be logged.
  *
  * @param  LogRecord
  * @param  string    A preformatted message, compiled by the <samp>filter</samp> 
  *                   method, containing <samp>$record->getMessage()</samp> and/or 
  *                   <samp>ABException::format($record->getThrown())</samp>
  * @return void
  * @throws SQLiteException
  */
 public function insertRecord(LogRecord $rec, $formattedMessage)
 {
     # compile final sql
     $sql = $this->insertSQL;
     foreach ($this->parameters['db.columns'] as $col) {
         if ($col == 'time') {
             $sql .= $rec->getTime();
         } elseif ($col == 'level') {
             $sql .= $rec->getLevel();
         } elseif ($col == 'prefix') {
             $sql .= "'" . sqlite_escape_string($rec->getPrefix()) . "'";
         } elseif ($col == 'message') {
             $sql .= "'" . sqlite_escape_string($formattedMessage) . "'";
         } elseif ($col == 'cwd') {
             $sql .= "'" . sqlite_escape_string(getcwd()) . "'";
         } else {
             continue;
         }
         $sql .= ',';
     }
     $sql = trim($sql, ',') . ');';
     $this->run($sql);
 }