|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* @file |
|
5
|
|
|
* Fires watchdog messages to mongodb. |
|
6
|
|
|
*/ |
|
7
|
|
|
|
|
8
|
|
|
/* ==== Everything below this line is broken ================================ */ |
|
9
|
|
|
|
|
10
|
|
|
/** |
|
11
|
|
|
* Load a MongoDB watchdog event. |
|
12
|
|
|
* |
|
13
|
|
|
* @param string $id |
|
14
|
|
|
* The event id. |
|
15
|
|
|
* |
|
16
|
|
|
* @return object|false |
|
17
|
|
|
* A loaded event. |
|
18
|
|
|
*/ |
|
19
|
|
|
function mongodb_watchdog_event_load($id) { |
|
20
|
|
|
$result = mongodb_collection(variable_get('mongodb_watchdog', 'watchdog')) |
|
|
|
|
|
|
21
|
|
|
->findOne(array('_id' => $id)); |
|
22
|
|
|
return $result ? $result : FALSE; |
|
23
|
|
|
} |
|
24
|
|
|
|
|
25
|
|
|
/** |
|
26
|
|
|
* Implements hook_watchdog(). |
|
27
|
|
|
* |
|
28
|
|
|
* Refer to issue #1355808 regarding filtering. |
|
29
|
|
|
* |
|
30
|
|
|
* @link http://drupal.org/node/1355808 @endlink |
|
31
|
|
|
*/ |
|
32
|
|
|
function mongodb_watchdog_watchdog(array $log_entry) { |
|
33
|
|
|
$watchdog_limit = variable_get('watchdog_limit', WATCHDOG_DEBUG); |
|
34
|
|
|
if (isset($log_entry['severity']) && $log_entry['severity'] > $watchdog_limit) { |
|
35
|
|
|
return; |
|
36
|
|
|
} |
|
37
|
|
|
|
|
38
|
|
|
static $checked_ids = array(); |
|
39
|
|
|
|
|
40
|
|
|
// Find the function that generated this error. |
|
41
|
|
|
$log_entry = (array) $log_entry; |
|
42
|
|
|
_mongodb_watchdog_enhance_log_entry($log_entry, debug_backtrace()); |
|
43
|
|
|
$account = $log_entry['user']; |
|
44
|
|
|
// Special handling for core bug #904994: |
|
45
|
|
|
if (!isset($log_entry['variables'])) { |
|
46
|
|
|
$special_messages = array( |
|
47
|
|
|
'page not found' => 'Page not found: @param', |
|
48
|
|
|
'access denied' => 'Access denied: @param', |
|
49
|
|
|
); |
|
50
|
|
|
$type = $log_entry['type']; |
|
51
|
|
|
$log_entry['variables'] = array('@param' => $log_entry['message']); |
|
52
|
|
|
$log_entry['message'] = isset($special_messages[$type]) |
|
53
|
|
|
? $special_messages[$log_entry['type']] |
|
54
|
|
|
: '@param'; |
|
55
|
|
|
} |
|
56
|
|
|
|
|
57
|
|
|
$event = array( |
|
58
|
|
|
'variables' => $log_entry['variables'], |
|
59
|
|
|
'timestamp' => $log_entry['timestamp'], |
|
60
|
|
|
'user' => array( |
|
61
|
|
|
'name' => isset($account->name) ? $account->name : variable_get('anonymous', t('Anonymous')), |
|
62
|
|
|
'uid' => $log_entry['uid'], |
|
63
|
|
|
), |
|
64
|
|
|
'ip' => $log_entry['ip'], |
|
65
|
|
|
'request_uri' => $log_entry['request_uri'], |
|
66
|
|
|
'referer' => $log_entry['referer'], |
|
67
|
|
|
'link' => $log_entry['link'], |
|
68
|
|
|
); |
|
69
|
|
|
unset($log_entry['variables'], $log_entry['user'], $log_entry['ip'], $log_entry['request_uri'], $log_entry['referer'], $log_entry['link']); |
|
70
|
|
|
|
|
71
|
|
|
$newobj = array( |
|
72
|
|
|
'$set' => $log_entry, |
|
73
|
|
|
'$inc' => array('count' => 1), |
|
74
|
|
|
); |
|
75
|
|
|
$collection = mongodb_collection(variable_get('mongodb_watchdog', 'watchdog')); |
|
76
|
|
|
$id = md5($log_entry['function'] . ':' . $log_entry['line'] . ':' . $log_entry['severity'] . ':' . $log_entry['type'] . ':' . $log_entry['message']); |
|
77
|
|
|
if (!isset($checked_ids[$id])) { |
|
78
|
|
|
$checked_ids[$id] = $collection->findOne(array('_id' => $id), array('_id' => 1)); |
|
|
|
|
|
|
79
|
|
|
} |
|
80
|
|
|
$collection->update(array('_id' => $id), $newobj, array('upsert' => TRUE) + mongodb_default_write_options(FALSE)); |
|
|
|
|
|
|
81
|
|
|
$collection = $collection->db->selectCollection('watchdog_event_' . $id); |
|
82
|
|
|
if (empty($checked_ids[$id])) { |
|
83
|
|
|
$max = variable_get('mongodb_watchdog_items', 10000); |
|
84
|
|
|
$command = array( |
|
85
|
|
|
'create' => $collection->getName(), |
|
86
|
|
|
'capped' => TRUE, |
|
87
|
|
|
'size' => $max * 1000, |
|
88
|
|
|
"max" => $max, |
|
89
|
|
|
); |
|
90
|
|
|
$collection->db->command($command); |
|
91
|
|
|
$checked_ids[$id] = TRUE; |
|
92
|
|
|
} |
|
93
|
|
|
$collection->insert($event, mongodb_default_write_options(FALSE)); |
|
94
|
|
|
} |
|
95
|
|
|
|
It seems like the method you are trying to call exists only in some of the possible types.
Let’s take a look at an example:
Available Fixes
Add an additional type-check:
Only allow a single type to be passed if the variable comes from a parameter: