You are here

function filelog_path in File Log 6.2

1 call to filelog_path()
filelog_watchdog in ./filelog.module
Implementation of hook_watchdog().

File

./filelog.module, line 160
Writes logging messages into files.

Code

function filelog_path($entry) {
  static $path;
  if (!is_null($path)) {
    return $path;
  }
  if (!($dir = filelog_directory())) {
    $path = FALSE;
    return FALSE;
  }
  $f = _filelog_get_conf();
  $name = array();
  $cache = TRUE;
  if ($f['site_in_name']) {
    $name[] = $f['site_in_name'] === TRUE ? array_pop(explode('/', conf_path())) : $f['site_in_name'];
  }
  if ($f['type_in_name']) {
    $name[] = preg_replace('|\\s+|', '_', $entry['type']);
    $cache = FALSE;
  }
  else {
    if (!$f['site_in_name']) {
      $name[] = 'watchdog';
    }
  }
  if ($f['daily_files']) {
    $name[] = format_date(time(), 'custom', 'Ymd');
  }
  if ($f['severity_in_name']) {
    if ($f['group_severity_in_name']) {
      switch ($entry['severity']) {
        case WATCHDOG_DEBUG:
          $name[] = 'debug';
          break;
        case WATCHDOG_INFO:
        case WATCHDOG_NOTICE:
        case WATCHDOG_WARNING:
          $name[] = 'info';
          break;
        case WATCHDOG_ERROR:
        case WATCHDOG_CRITICAL:
        case WATCHDOG_ALERT:
        case WATCHDOG_EMERG:
          $name[] = 'error';
          break;
      }
    }
    else {
      $name[] = _filelog_decode_severity($entry['severity']);
    }
    $cache = FALSE;
  }
  $name[] = $f['with_ui'] ? 'ui-log' : 'log';
  $file = $dir . '/' . implode('.', $name);
  if (!file_exists($file)) {
    if (touch($file)) {
      if ($f['chmod']) {
        chmod($file, $f['chmod']);
      }

      //realpath() should be used, because apache changes the working directory during shutdown,

      //which breaks logging when buffer is on.
      $file = realpath($file);
    }
    else {
      $cache = FALSE;
    }
  }
  if ($cache) {
    $path = $file;
  }
  return $file;
}