Example #1
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);
 }
Example #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);
 }
Example #3
0
 public function testDelete()
 {
     $path = $this->getPath('delete.log');
     $path2 = $path . '.2';
     rex_file::put($path, '');
     rex_file::put($path2, '');
     rex_log_file::delete($path);
     $this->assertFileNotExists($path);
     $this->assertFileNotExists($path2);
 }
Example #4
0
/**
 * Verwaltung der Content Sprachen.
 *
 * @package redaxo5
 */
// -------------- Defaults
$func = rex_request('func', 'string');
$error = '';
$success = '';
$logFile = rex_path::cache('system.log');
if ($func == 'delLog') {
    // close logger, to free remaining file-handles to syslog
    // so we can safely delete the file
    rex_logger::close();
    if (rex_log_file::delete($logFile)) {
        $success = rex_i18n::msg('syslog_deleted');
    } else {
        $error = rex_i18n::msg('syslog_delete_error');
    }
}
$message = '';
$content = '';
if ($success != '') {
    $message .= rex_view::success($success);
}
if ($error != '') {
    $message .= rex_view::error($error);
}
$content .= '
            <table class="table table-hover">