3 * StatusNet - the distributed open-source microblogging tool
4 * Copyright (C) 2010, StatusNet, Inc.
6 * This program is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU Affero General Public License as published by
8 * the Free Software Foundation, either version 3 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU Affero General Public License for more details.
16 * You should have received a copy of the GNU Affero General Public License
17 * along with this program. If not, see <http://www.gnu.org/licenses/>.
20 if (!defined('STATUSNET')) {
25 * Example to disable all debug messages and those containing 'About to push':
26 * addPlugin('LogFilter', array(
27 * 'priority' => array(LOG_DEBUG => false),
28 * 'regex' => array('/About to push/' => false)
31 * @todo add an admin panel
33 * @package LogFilterPlugin
34 * @maintainer Brion Vibber <brion@status.net>
36 class LogFilterPlugin extends Plugin
38 public $default = true; // Set to false to require opting things in
39 public $priority = array(); // override by priority: array(LOG_ERR => true, LOG_DEBUG => false)
40 public $regex = array(); // override by regex match of message: array('/twitter/i' => false)
42 function onPluginVersion(array &$versions)
44 $versions[] = array('name' => 'LogFilter',
45 'version' => GNUSOCIAL_VERSION,
46 'author' => 'Brion Vibber',
47 'homepage' => 'http://status.net/wiki/Plugin:LogFilter',
49 // TRANS: Plugin description.
50 _m('Provides server-side setting to filter log output by type or keyword.'));
56 * Hook for the StartLog event in common_log().
57 * If a message doesn't pass our filters, we'll abort it.
59 * @param string $priority
61 * @param string $filename
62 * @return boolean hook result code
64 function onStartLog(&$priority, &$msg, &$filename)
66 if ($this->filter($priority, $msg)) {
70 // Abort -- this line will go to /dev/null :)
78 * @param string $priority
80 * @return boolean true to let the log message be processed
82 function filter($priority, $msg)
84 $state = $this->default;
85 if (array_key_exists($priority, $this->priority)) {
86 $state = $this->priority[$priority];
88 foreach ($this->regex as $regex => $override) {
89 if (preg_match($regex, $msg)) {