You are here

lagoon_logs.module in Lagoon Logs 7

File

lagoon_logs.module
View source
<?php

require_once __DIR__ . "/lib/LagoonLogger.php";
require_once __DIR__ . "/lib/LagoonLogstashFormatter.php";
require_once __DIR__ . "/lib/LagoonLogstashPusher.php";

/**
 * Implements hook_menu()
 */
function lagoon_logs_menu() {
  return [
    'admin/config/system/lagoon_logs' => [
      'title' => 'Lagoon Logs Settings',
      'description' => 'Displays effective settings for current Lagoon Logs setup (read only)',
      'page callback' => 'drupal_get_form',
      'page arguments' => [
        'lagoon_logs_settings_display',
      ],
      'access arguments' => [
        'administer site configuration',
      ],
      'type' => MENU_NORMAL_ITEM,
    ],
  ];
}

/**
 * Form to display current Lagoon Logs settings (READ ONLY)
 */
function lagoon_logs_settings_display() {
  $form = [];
  $form['lagoon_logs_enabled'] = array(
    '#type' => 'checkbox',
    '#title' => t('Enabled'),
    '#description' => t('Send logs to Lagoon or not.'),
    '#default_value' => variable_get('lagoon_logs_enabled', TRUE),
  );
  $form['lagoon_logs_description'] = [
    '#prefix' => '<div class="ll-settings-description">',
    '#suffix' => '</div>',
    '#markup' => t('Current settings for the Lagoon Logs module. The defaults are set in configuration, this is meant primarily for troubleshooting.'),
  ];
  $form['lagoon_logs_host'] = [
    '#prefix' => '<div class="ll-settings-key-value">',
    '#suffix' => '</div>',
    '#markup' => t('Logstash host: ') . variable_get('LAGOON_LOGS_HOST', LagoonLogger::LAGOON_LOGS_DEFAULT_HOST),
  ];
  $form['lagoon_logs_port'] = [
    '#prefix' => '<div class="ll-settings-key-value">',
    '#suffix' => '</div>',
    '#markup' => t('Logstash port: ') . variable_get('LAGOON_LOGS_PORT', LagoonLogger::LAGOON_LOGS_DEFAULT_PORT),
  ];
  $form['lagoon_logs_identifier'] = [
    '#prefix' => '<div class="ll-settings-key-value">',
    '#suffix' => '</div>',
    '#markup' => t('Logstash leading identifier: ') . variable_get('LAGOON_LOGS_IDENTIFIER', LagoonLogger::LAGOON_LOGS_DEFAULT_IDENTIFIER),
  ];
  return system_settings_form($form);
}

/**
 * Implements hook_watchdog()
 */
function lagoon_logs_watchdog(array $log_entry) {
  if (variable_get('lagoon_logs_enabled', TRUE)) {
    if ($log_entry['type'] != LagoonLogger::LAGOON_LOGGER_WATCHDOG_FALLBACK_IDENTIFIER) {
      $logger = LagoonLogger::getLogger(variable_get('LAGOON_LOGS_HOST', LagoonLogger::LAGOON_LOGS_DEFAULT_HOST), variable_get('LAGOON_LOGS_PORT', LagoonLogger::LAGOON_LOGS_DEFAULT_PORT), variable_get('LAGOON_LOGS_IDENTIFIER', LagoonLogger::LAGOON_LOGS_DEFAULT_IDENTIFIER));
      $logger
        ->log($log_entry);
    }
  }
}

Functions

Namesort descending Description
lagoon_logs_menu Implements hook_menu()
lagoon_logs_settings_display Form to display current Lagoon Logs settings (READ ONLY)
lagoon_logs_watchdog Implements hook_watchdog()