Skip to content

Commit

Permalink
Create setting to disable logging to db
Browse files Browse the repository at this point in the history
  • Loading branch information
zuuperman committed Sep 19, 2013
1 parent 4e4baaa commit defed02
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 15 deletions.
2 changes: 1 addition & 1 deletion culturefeed_devel/culturefeed_devel.info
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@ description = Enables query logging for culturefeed requests. Only search reques
package = CultureFeed
version = VERSION
core = 7.x
configure = admin/config/development/devel
configure = admin/config/development/culturefeed
dependencies[] = culturefeed_search
19 changes: 11 additions & 8 deletions culturefeed_devel/culturefeed_devel.module
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@ define('CULTUREFEED_DEVEL_DEFAULT_SLOW_REQUEST', 100);
* Implementation of hook_boot(). Runs even for cached pages.
*/
function culturefeed_devel_boot() {
drupal_register_shutdown_function('culturefeed_devel_shutdown');
if (variable_get('culturefeed_devel_log_slow_request', FALSE) || variable_get('culturefeed_devel_show_requests', TRUE)) {
drupal_register_shutdown_function('culturefeed_devel_shutdown');
}
}

/**
Expand Down Expand Up @@ -77,7 +79,6 @@ function culturefeed_devel_menu() {
*/
function culturefeed_devel_shutdown() {


// Search api requests.
$requests = \CultuurNet\Auth\Guzzle\Log\RequestLog::getInstance()->getRequests();

Expand All @@ -87,12 +88,14 @@ function culturefeed_devel_shutdown() {

$max_time = variable_get('culturefeed_devel_slow_request', CULTUREFEED_DEVEL_DEFAULT_SLOW_REQUEST);

foreach ($requests as $request) {
if ($request->getTime() > $max_time) {
watchdog('culturefeed_devel', t('Slow query on api: @query. Time taken: @time ms', array(
'@query' => urldecode($request->getUrl()),
'@time' => $request->getTime(),
)));
if (variable_get('culturefeed_devel_log_slow_request', FALSE)) {
foreach ($requests as $request) {
if ($request->getTime() > $max_time) {
watchdog('culturefeed_devel', t('Slow query on api: @query. Time taken: @time ms', array(
'@query' => urldecode($request->getUrl()),
'@time' => $request->getTime(),
)));
}
}
}

Expand Down
15 changes: 10 additions & 5 deletions culturefeed_devel/includes/admin.inc
Original file line number Diff line number Diff line change
Expand Up @@ -12,22 +12,27 @@ function culturefeed_devel_admin_settings_form() {

$form = array();

$form['culturefeed_devel_slow_request'] = array(
'#type' => 'textfield',
'#title' => t('Log requests slower then'),
$form['culturefeed_devel_log_slow_request'] = array(
'#type' => 'checkbox',
'#title' => t('Log slow requests'),
'#description' => t('Requests that where slower then the entered milliseconds
will be logged to the watchdog'),
'#default_value' => variable_get('culturefeed_devel_slow_request', CULTUREFEED_DEVEL_DEFAULT_SLOW_REQUEST),
'#default_value' => variable_get('culturefeed_devel_log_slow_request', FALSE),
);


$form['culturefeed_devel_show_requests'] = array(
'#type' => 'checkbox',
'#title' => t('Display full requests log'),
'#description' => t('All requests will be shown in the footer of the page'),
'#default_value' => variable_get('culturefeed_devel_show_requests', TRUE),
);

$form['culturefeed_devel_slow_request'] = array(
'#type' => 'textfield',
'#title' => t('Mark requests slower then'),
'#description' => t('Queries slower then the entered milliseconds will be seen as slow'),
'#default_value' => variable_get('culturefeed_devel_slow_request', CULTUREFEED_DEVEL_DEFAULT_SLOW_REQUEST),
);

return system_settings_form($form);
}
Expand Down
2 changes: 1 addition & 1 deletion culturefeed_search_ui/lib/Drupal/CultureFeedSearchPage.php
Original file line number Diff line number Diff line change
Expand Up @@ -570,7 +570,7 @@ protected function build() {
$build['pager-container']['pager'] = array(
'#type' => 'link',
'#title' => t('More results'),
'#href' => strpos('nojs') === FALSE ? $_GET['q'] . '/nojs' : $_GET['q'],
'#href' => strpos('nojs', $_GET['q']) === FALSE ? $_GET['q'] . '/nojs' : $_GET['q'],
'#options' => array('query' => $params),
'#ajax' => array(),
'#attributes' => array(
Expand Down

0 comments on commit defed02

Please sign in to comment.