ILIAS  release_5-1 Revision 5.0.0-5477-g43f3e3fab5f
FleepHookHandler.php
Go to the documentation of this file.
1<?php
2
3/*
4 * This file is part of the Monolog package.
5 *
6 * (c) Jordi Boggiano <j.boggiano@seld.be>
7 *
8 * For the full copyright and license information, please view the LICENSE
9 * file that was distributed with this source code.
10 */
11
12namespace Monolog\Handler;
13
16
26{
27 const FLEEP_HOST = 'fleep.io';
28
29 const FLEEP_HOOK_URI = '/hook/';
30
34 protected $token;
35
47 public function __construct($token, $level = Logger::DEBUG, $bubble = true)
48 {
49 if (!extension_loaded('openssl')) {
50 throw new MissingExtensionException('The OpenSSL PHP extension is required to use the FleepHookHandler');
51 }
52
53 $this->token = $token;
54
55 $connectionString = 'ssl://' . self::FLEEP_HOST . ':443';
56 parent::__construct($connectionString, $level, $bubble);
57 }
58
66 protected function getDefaultFormatter()
67 {
68 return new LineFormatter(null, null, true, true);
69 }
70
76 public function write(array $record)
77 {
78 parent::write($record);
79 $this->closeSocket();
80 }
81
88 protected function generateDataStream($record)
89 {
90 $content = $this->buildContent($record);
91
92 return $this->buildHeader($content) . $content;
93 }
94
101 private function buildHeader($content)
102 {
103 $header = "POST " . self::FLEEP_HOOK_URI . $this->token . " HTTP/1.1\r\n";
104 $header .= "Host: " . self::FLEEP_HOST . "\r\n";
105 $header .= "Content-Type: application/x-www-form-urlencoded\r\n";
106 $header .= "Content-Length: " . strlen($content) . "\r\n";
107 $header .= "\r\n";
108
109 return $header;
110 }
111
118 private function buildContent($record)
119 {
120 $dataArray = array(
121 'message' => $record['formatted']
122 );
123
124 return http_build_query($dataArray);
125 }
126}
Formats incoming records into a one-line string.
Sends logs to Fleep.io using Webhook integrations.
write(array $record)
Handles a log record.
buildContent($record)
Builds the body of API call.
buildHeader($content)
Builds the header of the API Call.
getDefaultFormatter()
Returns the default formatter to use with this handler.
__construct($token, $level=Logger::DEBUG, $bubble=true)
Construct a new Fleep.io Handler.
Exception can be thrown if an extension for an handler is missing.
Stores to any socket - uses fsockopen() or pfsockopen().
closeSocket()
Close socket, if open.
Monolog log channel.
Definition: Logger.php:28
const DEBUG
Detailed debug information.
Definition: Logger.php:32
$header