PSR-2. I'm not a huge fan, but ugly consistency beats no consistency...

This commit is contained in:
Shish
2019-05-28 17:59:38 +01:00
parent 5ec3e89884
commit 34b05cca7c
295 changed files with 27094 additions and 24632 deletions

View File

@ -7,43 +7,48 @@
* Visibility: admin
*/
class LogNet extends Extension {
private $count = 0;
class LogNet extends Extension
{
private $count = 0;
public function onLog(LogEvent $event) {
global $user;
public function onLog(LogEvent $event)
{
global $user;
if($event->priority > 10) {
$this->count++;
if($this->count < 10) {
// TODO: colour based on event->priority
$username = ($user && $user->name) ? $user->name : "Anonymous";
$str = sprintf("%-15s %-10s: %s", $_SERVER['REMOTE_ADDR'], $username, $event->message);
$this->msg($str);
}
else if($this->count == 10) {
$this->msg('suppressing flood, check the web log');
}
}
}
if ($event->priority > 10) {
$this->count++;
if ($this->count < 10) {
// TODO: colour based on event->priority
$username = ($user && $user->name) ? $user->name : "Anonymous";
$str = sprintf("%-15s %-10s: %s", $_SERVER['REMOTE_ADDR'], $username, $event->message);
$this->msg($str);
} elseif ($this->count == 10) {
$this->msg('suppressing flood, check the web log');
}
}
}
private function msg($data) {
global $config;
$host = $config->get_string("log_net_host", "127.0.0.1:35353");
private function msg($data)
{
global $config;
$host = $config->get_string("log_net_host", "127.0.0.1:35353");
if(!$host) { return; }
if (!$host) {
return;
}
try {
$parts = explode(":", $host);
$host = $parts[0];
$port = $parts[1];
$fp = fsockopen("udp://$host", $port, $errno, $errstr);
if (! $fp) { return; }
fwrite($fp, "$data\n");
fclose($fp);
} catch (Exception $e) {
/* logging errors shouldn't break everything */
}
}
try {
$parts = explode(":", $host);
$host = $parts[0];
$port = $parts[1];
$fp = fsockopen("udp://$host", $port, $errno, $errstr);
if (! $fp) {
return;
}
fwrite($fp, "$data\n");
fclose($fp);
} catch (Exception $e) {
/* logging errors shouldn't break everything */
}
}
}