Beispiel #1
0
    /**
     * @depends testConstruct
     */
    public function testAdd()
    {
        $path = $this->getPath('test3.log');
        $log = new rex_log_file($path);
        $log->add(['test1a', 'test1b']);
        $log->add(['test2a', 'test2b', 'test2c']);
        $format = <<<'EOF'
%i-%i-%i %i:%i:%i | test1a | test1b
%i-%i-%i %i:%i:%i | test2a | test2b | test2c
EOF;
        $this->assertStringMatchesFormat($format, rex_file::get($path));
    }
Beispiel #2
0
 /**
  * Logs with an arbitrary level.
  *
  * @param mixed  $level
  * @param string $message
  * @param array  $context
  * @param string $file
  * @param int    $line
  *
  * @throws InvalidArgumentException
  */
 public function log($level, $message, array $context = [], $file = null, $line = null)
 {
     if (static::hasFactoryClass()) {
         static::callFactoryClass(__FUNCTION__, func_get_args());
         return;
     }
     if (!is_string($message)) {
         throw new InvalidArgumentException('Expecting $message to be string, but ' . gettype($message) . ' given!');
     }
     self::open();
     // build a replacement array with braces around the context keys
     $replace = [];
     foreach ($context as $key => $val) {
         $replace['{' . $key . '}'] = $val;
     }
     // interpolate replacement values into the message and return
     $message = strtr($message, $replace);
     $logData = [$level, $message];
     if ($file && $line) {
         $logData[] = str_replace(rex_path::base(), '', $file);
         $logData[] = $line;
     }
     self::$file->add($logData);
     // forward the error into phps' error log
     error_log($message, 0);
 }
Beispiel #3
0
 public function log($success, $message)
 {
     $name = $this->name;
     if (!$name) {
         if ($this->cronjob instanceof rex_cronjob) {
             $name = rex::isBackend() ? $this->cronjob->getTypeName() : $this->cronjob->getType();
         } else {
             $name = '[no name]';
         }
     }
     $log = new rex_log_file(rex_path::addonData('cronjob', 'cronjob.log'), 2000000);
     $data = [$success ? 'SUCCESS' : 'ERROR', $this->id ?: '--', $name, strip_tags($message)];
     $log->add($data);
 }