Skip to content
Snippets Groups Projects
Commit ec2dffe4 authored by Demian Katz's avatar Demian Katz
Browse files

Implemented dynamic debug mode.

parent 137ec312
Branches
Tags
No related merge requests found
...@@ -9,7 +9,8 @@ ...@@ -9,7 +9,8 @@
; up during ILS maintenance. ; up during ILS maintenance.
available = true available = true
; Change to true to see messages about the behavior of the system as part of the ; Change to true to see messages about the behavior of the system as part of the
; output -- only for use when troubleshooting problems: ; output -- only for use when troubleshooting problems. See also the access.DebugMode
; setting in permissions.ini to turn on debug using a GET parameter in the request.
debug = false debug = false
; This setting should be set to false after auto-configuration is complete ; This setting should be set to false after auto-configuration is complete
autoConfigure = true autoConfigure = true
......
...@@ -61,6 +61,7 @@ ...@@ -61,6 +61,7 @@
; List of permissions that you may wish to configure: ; List of permissions that you may wish to configure:
; ;
; access.AdminModule - Controls access to the admin panel (if enabled in config.ini) ; access.AdminModule - Controls access to the admin panel (if enabled in config.ini)
; access.DebugMode - Allows ?debug=true GET parameter to turn on debug mode
; access.EITModule - Controls access to the EBSCO EIT module (if active) ; access.EITModule - Controls access to the EBSCO EIT module (if active)
; access.StaffViewTab - Controls access to the staff view tab in record mode ; access.StaffViewTab - Controls access to the staff view tab in record mode
; access.SummonExtendedResults - Controls visibility of protected Summon results ; access.SummonExtendedResults - Controls visibility of protected Summon results
...@@ -76,6 +77,11 @@ role[] = guest ...@@ -76,6 +77,11 @@ role[] = guest
role[] = loggedin role[] = loggedin
permission = access.StaffViewTab permission = access.StaffViewTab
; Example for dynamic debug mode
;[default.DebugMode]
;username[] = admin
;permission = access.DebugMode
; Examples for Shibboleth ; Examples for Shibboleth
; ;
; Only users that have either common-lib-terms and entityid from idp1 or ; Only users that have either common-lib-terms and entityid from idp1 or
......
...@@ -146,6 +146,25 @@ class Bootstrapper ...@@ -146,6 +146,25 @@ class Bootstrapper
$serviceManager->get('VuFind\AuthManager')->checkForExpiredCredentials(); $serviceManager->get('VuFind\AuthManager')->checkForExpiredCredentials();
} }
/**
* Initialize dynamic debug mode.
*
* @return void
*/
protected function initDynamicDebug()
{
$app = $this->event->getApplication();
$sm = $app->getServiceManager();
$debugOverride = $sm->get('Request')->getQuery()->get('debug');
if ($debugOverride) {
$auth = $sm->get('ZfcRbac\Service\AuthorizationService');
if ($auth->isGranted('access.DebugMode')) {
$logger = $sm->get('VuFind\Logger');
$logger->addDebugWriter($debugOverride);
}
}
}
/** /**
* If the system is offline, set up a handler to override the routing output. * If the system is offline, set up a handler to override the routing output.
* *
......
...@@ -61,18 +61,9 @@ class Logger extends BaseLogger implements ServiceLocatorAwareInterface ...@@ -61,18 +61,9 @@ class Logger extends BaseLogger implements ServiceLocatorAwareInterface
{ {
// DEBUGGER // DEBUGGER
if (!$config->System->debug == false) { if (!$config->System->debug == false) {
$writer = new Writer\Stream('php://output'); $this->addDebugWriter($config->System->debug);
$formatter = new \Zend\Log\Formatter\Simple(
'<pre>%timestamp% %priorityName%: %message%</pre>' . PHP_EOL
);
$writer->setFormatter($formatter);
$this->addWriters(
$writer,
'debug-'
. (is_int($config->System->debug) ? $config->System->debug : '5')
);
} }
// Activate database logging, if applicable: // Activate database logging, if applicable:
if (isset($config->Logging->database)) { if (isset($config->Logging->database)) {
$parts = explode(':', $config->Logging->database); $parts = explode(':', $config->Logging->database);
...@@ -135,6 +126,30 @@ class Logger extends BaseLogger implements ServiceLocatorAwareInterface ...@@ -135,6 +126,30 @@ class Logger extends BaseLogger implements ServiceLocatorAwareInterface
} }
} }
/**
* Add the standard debug stream writer.
*
* @param bool|int $debug Debug mode/level
*
* @return void
*/
public function addDebugWriter($debug)
{
// Only add debug writer ONCE!
static $hasDebugWriter = false;
if ($hasDebugWriter) {
return;
}
$hasDebugWriter = true;
$writer = new Writer\Stream('php://output');
$formatter = new \Zend\Log\Formatter\Simple(
'<pre>%timestamp% %priorityName%: %message%</pre>' . PHP_EOL
);
$writer->setFormatter($formatter);
$this->addWriters($writer, 'debug-' . (is_int($debug) ? $debug : '5'));
}
/** /**
* Applies an array of filters to a writer * Applies an array of filters to a writer
* *
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment