Skip to content

Commit

Permalink
initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
pianomansam committed Apr 13, 2018
1 parent 2fdf912 commit 84f429b
Show file tree
Hide file tree
Showing 4 changed files with 111 additions and 0 deletions.
21 changes: 21 additions & 0 deletions handlers/rdg_error_log_json.inc
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?php

/**
* @file
* Handler include for ErrorLogHandler.
*/

use Monolog\Handler\ErrorLogHandler;
use Monolog\Formatter\JsonFormatter;

/**
* Monolog loader callback; Loads a ErrorLogHandler handler.
*
* @return HandlerInterface
*/
function monolog_rdg_error_log_json_handler_loader($options) {
$handler = new ErrorLogHandler(ErrorLogHandler::OPERATING_SYSTEM, $options['level'], $options['bubble']);
$formatter = new JsonFormatter();
$handler->setFormatter($formatter);
return $handler;
}
44 changes: 44 additions & 0 deletions handlers/rdg_rotating_file_json.inc
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
<?php

/**
* @file
* Handler include for StreamHandler.
*/

use Monolog\Handler\RotatingFileHandler;
use Monolog\Formatter\JsonFormatter;

/**
* Monolog loader callback; Loads a RotatingFileHandler handler.
*
* @return HandlerInterface
*/
function monolog_rdg_rotating_file_json_handler_loader($options) {
$directory = dirname($options['filepath']);
monolog_prepare_log_dir($directory);
$handler = new RotatingFileHandler($options['filepath'], $options['max_files'], $options['level'], $options['bubble']);
$formatter = new JsonFormatter();
$handler->setFormatter($formatter);
return $handler;
}

/**
* Monolog settings form; Settings for the RotatingFileHandler handler.
*/
function monolog_rdg_rotating_file_json_handler_settings(&$form, &$form_state, $profile, array $handler) {

$form['filepath'] = array(
'#title' => t('Log file path'),
'#type' => 'textfield',
'#default_value' => $handler['filepath'],
'#description' => t('The path or URI that the log file will be written to.'),
);

$form['max_files'] = array(
'#title' => t('Maximum number of files'),
'#type' => 'textfield',
'#default_value' => $handler['max_files'],
'#description' => t('The maximal amount of files to keep (0 means unlimited).'),
'#size' => 4,
);
}
7 changes: 7 additions & 0 deletions rdg_monolog.info
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
name = RDG Monolog
description = Additional Monolog Handlers from Rapid Development Group
package = Rapid Development Group
version = 7.x-1.0
core = 7.x

dependencies[] = monolog
39 changes: 39 additions & 0 deletions rdg_monolog.module
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<?php

/**
* @file
* Monolog hook implementations.
*/

/**
* Implements hook_monolog_handler_path().
*/
function rdg_monolog_monolog_handler_path() {
return 'handlers';
}

/**
* Implements hook_monolog_handler_info().
*/
function rdg_monolog_monolog_handler_info() {
$handlers = array();

$handlers['rdg_rotating_file_json'] = array(
'label' => t('RDG Rotating File Handler - JSON'),
'description' => t('Logs records to a file and creates one logfile per day. It will also delete files older than the "Max Files" settings.'),
'group' => t('Files and syslog'),
'default settings' => array(
'filepath' => 'private://log/drupal.log',
'max_files' => 0,
),
);

$handlers['rdg_error_log_json'] = array(
'label' => t('RDG ErrorLogHandler Handler - JSON'),
'description' => t('Handler for ErrorLogHandler, logging records to PHP\'s error_log() function.'),
'group' => t('Development'),
'settings callback' => FALSE,
);

return $handlers;
}

0 comments on commit 84f429b

Please sign in to comment.