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,49 +7,55 @@
* Visibility: admin
*/
class LogLogstash extends Extension {
public function onLog(LogEvent $event) {
global $user;
class LogLogstash extends Extension
{
public function onLog(LogEvent $event)
{
global $user;
try {
$data = array(
"@type" => "shimmie",
"@message" => $event->message,
"@fields" => array(
"username" => ($user && $user->name) ? $user->name : "Anonymous",
"section" => $event->section,
"priority" => $event->priority,
"time" => $event->time,
"args" => $event->args,
),
#"@request" => $_SERVER,
"@request" => array(
"UID" => get_request_id(),
"REMOTE_ADDR" => $_SERVER['REMOTE_ADDR'],
),
);
try {
$data = [
"@type" => "shimmie",
"@message" => $event->message,
"@fields" => [
"username" => ($user && $user->name) ? $user->name : "Anonymous",
"section" => $event->section,
"priority" => $event->priority,
"time" => $event->time,
"args" => $event->args,
],
#"@request" => $_SERVER,
"@request" => [
"UID" => get_request_id(),
"REMOTE_ADDR" => $_SERVER['REMOTE_ADDR'],
],
];
$this->send_data($data);
} catch (Exception $e) {
}
}
$this->send_data($data);
} catch (Exception $e) {
}
}
private function send_data($data) {
global $config;
private function send_data($data)
{
global $config;
$host = $config->get_string("log_logstash_host");
if(!$host) { return; }
$host = $config->get_string("log_logstash_host");
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, json_encode($data));
fclose($fp);
} catch (Exception $e) {
}
}
try {
$parts = explode(":", $host);
$host = $parts[0];
$port = $parts[1];
$fp = fsockopen("udp://$host", $port, $errno, $errstr);
if (! $fp) {
return;
}
fwrite($fp, json_encode($data));
fclose($fp);
} catch (Exception $e) {
}
}
}