-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdevel_debug_log.module
106 lines (93 loc) · 2.51 KB
/
devel_debug_log.module
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
<?php
/**
* @file
* Contains Drupal\devel_debug_log\devel_debug_log.module.
*/
/**
* Saves a debug message.
*
* @param mixed $message
* A debug message to save, which can be:
* - string: saved as it is;
* - object/array: serialized before saving;
*
* Currently, there's development going on regarding the serialization part,
* since most of the data in D8 contains references to injected services and
* maybe even plugins.
* A discussion about this topic can be found here:
* @see https://www.drupal.org/node/2705731
*
* @param string $title
* Title of the debug message.
*/
function ddl($message, $title = '') {
$serialized = FALSE;
$message = devel_debug_log_ob_kint($message);
// TODO Find a way to store the initial message, instead of storing the entire
// debug markup returned by kint().
$connection = \Drupal::database();
$query = $connection->insert('devel_debug_log')
->fields(array(
'timestamp' => REQUEST_TIME,
'title' => $title,
'message' => isset($message) ? $message : 'NULL',
'serialized' => $serialized ? 1 : 0,
));
$query->execute();
}
/**
* Checks if the message has already been saved during the current page request,
* and saves the message only if it is not a repetition of a previous one.
*
* @param $message
* A debug message to save, which can be:
* - string: saved as is.
* - object or array: saved serialized.
* @param string $title
* Title for the debug message.
*/
function ddl_once($message, $title = '') {
$message_history = &drupal_static(__FUNCTION__);
if (!isset($message_history)) {
$message_history = array();
}
$serialized = serialize($message);
$hash = md5($serialized);
if (in_array($hash, $message_history)) {
return;
}
$message_history[] = $hash;
ddl($message, $title);
}
/**
* Implements hook_theme().
*/
function devel_debug_log_theme($existing, $type, $theme, $path) {
return array(
'devel_debug_log_list' => array(
'variables' => array(
'content' => NULL,
'delete_form' => NULL,
),
)
);
}
/**
* Provides debug output for later printing.
*
* kint() outputs the debug information at the top of the page. This function
* allows you to get the output and use it for later printing.
*
* @param mixed $message
* The data that's displayed for debugging.
*
* @return string
* The debug information.
*/
function devel_debug_log_ob_kint($message) {
ob_start();
kint($message);
$output = ob_get_contents();
ob_end_clean();
return $output;
}