udp log_net, because it's faster and more elegant

This commit is contained in:
Shish 2012-06-22 19:19:13 +01:00
parent 7ed7f4bbb8
commit 8dcd56e0ec

View file

@ -19,12 +19,30 @@ class LogNet extends Extension {
// TODO: colour based on event->priority
$username = ($user && $user->name) ? $user->name : "Anonymous";
$str = sprintf("%-15s %-10s: %s", $_SERVER['REMOTE_ADDR'], $username, $event->message);
system("echo ".escapeshellarg($str)." | nc -q 0 localhost 5000");
$this->msg($str);
}
else if($this->count == 10) {
system("echo 'suppressing flood, check the web log' | nc -q 0 localhost 5000");
$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");
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) {
}
}
}
?>