You are here

function jsonlog_default_dir in JSONlog 8

Same name and namespace in other branches
  1. 8.2 jsonlog.inc \jsonlog_default_dir()
  2. 7.2 jsonlog.inc \jsonlog_default_dir()
  3. 3.x jsonlog.inc \jsonlog_default_dir()

Establish default logging dir.

Directory default: PHP:ini error_log - unless that is 'syslog' (then checks the usual suspects /var/log/...) - plus /drupal-jsonlog.

Return value

string Empty upon failure.

3 calls to jsonlog_default_dir()
JsonLog::loadDefaultSettings in src/Logger/JsonLog.php
Fetch all settings of this module.
jsonlog_form_system_logging_settings_submit in ./jsonlog.module
Custom submit handler for the system logging settings form.
_jsonlog_form_system_logging_settings_alter in ./jsonlog.inc
Adds this module's setting fields to the system logging settings form.

File

./jsonlog.inc, line 386
JSONlog module helper functions.

Code

function jsonlog_default_dir() {
  if ($dir = getenv('drupal_jsonlog_dir')) {
    return $dir;
  }

  // Default web server log dir for common *nix distributions.
  $default_log_dirs = [
    'debian' => '/var/log/apache2',
    'redhat' => '/var/log/httpd',
  ];
  $dir = '';
  if (!($server_log = ini_get('error_log')) || $server_log === 'syslog') {

    // Try default web server log dirs for common *nix distributions.
    foreach ($default_log_dirs as $val) {
      if (file_exists($val)) {
        $dir = $val;
        break;
      }
    }
  }
  else {
    $dir = str_replace('\\', '/', dirname($server_log));
  }
  if ($dir) {
    return $dir . '/drupal-jsonlog';
  }
  return '';
}