ILIAS  release_5-2 Revision v5.2.25-18-g3f80b82851
Monolog\Handler\CubeHandler Class Reference

Logs to Cube. More...

+ Inheritance diagram for Monolog\Handler\CubeHandler:
+ Collaboration diagram for Monolog\Handler\CubeHandler:

Public Member Functions

 __construct ($url, $level=Logger::DEBUG, $bubble=true)
 Create a Cube handler. More...
 
- Public Member Functions inherited from Monolog\Handler\AbstractProcessingHandler
 handle (array $record)
 {Handles a record.All records may be passed to this method, and the handler should discard those that it does not want to handle.The return value of this function controls the bubbling process of the handler stack. Unless the bubbling is interrupted (by returning true), the Logger class will keep on calling further handlers in the stack with a given log record.
Parameters
array$recordThe record to handle
Returns
Boolean true means that this handler handled the record, and that bubbling is not permitted. false means the record was either not processed or that this handler allows bubbling.
} More...
 
- Public Member Functions inherited from Monolog\Handler\AbstractHandler
 __construct ($level=Logger::DEBUG, $bubble=true)
 
 isHandling (array $record)
 {Checks whether the given record will be handled by this handler.This is mostly done for performance reasons, to avoid calling processors for nothing.Handlers should still check the record levels within handle(), returning false in isHandling() is no guarantee that handle() will not be called, and isHandling() might not be called for a given record.
Parameters
array$recordPartial log record containing only a level key
Returns
Boolean
} More...
 
 handleBatch (array $records)
 {Handles a set of records at once.
Parameters
array$recordsThe records to handle (an array of record arrays)
} More...
 
 close ()
 Closes the handler. More...
 
 pushProcessor ($callback)
 {Adds a processor in the stack.
Parameters
callable$callback
Returns
self
} More...
 
 popProcessor ()
 {Removes the processor on top of the stack and returns it.
Returns
callable
} More...
 
 setFormatter (FormatterInterface $formatter)
 {Sets the formatter.
Parameters
FormatterInterface$formatter
Returns
self
} More...
 
 getFormatter ()
 {Gets the formatter.
Returns
FormatterInterface
} More...
 
 setLevel ($level)
 Sets minimum logging level at which this handler will be triggered. More...
 
 getLevel ()
 Gets minimum logging level at which this handler will be triggered. More...
 
 setBubble ($bubble)
 Sets the bubbling behavior. More...
 
 getBubble ()
 Gets the bubbling behavior. More...
 
 __destruct ()
 

Protected Member Functions

 connectUdp ()
 Establish a connection to an UDP socket. More...
 
 connectHttp ()
 Establish a connection to a http server. More...
 
 write (array $record)
 {} More...
 
- Protected Member Functions inherited from Monolog\Handler\AbstractProcessingHandler
 write (array $record)
 Writes the record down to the log of the implementing handler. More...
 
 processRecord (array $record)
 Processes a record. More...
 
- Protected Member Functions inherited from Monolog\Handler\AbstractHandler
 getDefaultFormatter ()
 Gets the default formatter. More...
 

Private Member Functions

 writeUdp ($data)
 
 writeHttp ($data)
 

Private Attributes

 $udpConnection
 
 $httpConnection
 
 $scheme
 
 $host
 
 $port
 
 $acceptedSchemes = array('http', 'udp')
 

Additional Inherited Members

- Protected Attributes inherited from Monolog\Handler\AbstractHandler
 $level = Logger::DEBUG
 
 $bubble = true
 
 $formatter
 
 $processors = array()
 

Detailed Description

Logs to Cube.

Wan Chen kami@.nosp@m.kami.nosp@m.sama..nosp@m.me

Definition at line 22 of file CubeHandler.php.

Constructor & Destructor Documentation

◆ __construct()

Monolog\Handler\CubeHandler::__construct (   $url,
  $level = Logger::DEBUG,
  $bubble = true 
)

Create a Cube handler.

Exceptions

Definition at line 38 of file CubeHandler.php.

References Monolog\Handler\AbstractHandler\$bubble, Monolog\Handler\AbstractHandler\$level, and $url.

39  {
40  $urlInfo = parse_url($url);
41 
42  if (!isset($urlInfo['scheme'], $urlInfo['host'], $urlInfo['port'])) {
43  throw new \UnexpectedValueException('URL "'.$url.'" is not valid');
44  }
45 
46  if (!in_array($urlInfo['scheme'], $this->acceptedSchemes)) {
47  throw new \UnexpectedValueException(
48  'Invalid protocol (' . $urlInfo['scheme'] . ').'
49  . ' Valid options are ' . implode(', ', $this->acceptedSchemes));
50  }
51 
52  $this->scheme = $urlInfo['scheme'];
53  $this->host = $urlInfo['host'];
54  $this->port = $urlInfo['port'];
55 
56  parent::__construct($level, $bubble);
57  }
$url
Definition: shib_logout.php:72

Member Function Documentation

◆ connectHttp()

Monolog\Handler\CubeHandler::connectHttp ( )
protected

Establish a connection to a http server.

Exceptions

Definition at line 85 of file CubeHandler.php.

Referenced by Monolog\Handler\CubeHandler\writeHttp().

86  {
87  if (!extension_loaded('curl')) {
88  throw new \LogicException('The curl extension is needed to use http URLs with the CubeHandler');
89  }
90 
91  $this->httpConnection = curl_init('http://'.$this->host.':'.$this->port.'/1.0/event/put');
92 
93  if (!$this->httpConnection) {
94  throw new \LogicException('Unable to connect to ' . $this->host . ':' . $this->port);
95  }
96 
97  curl_setopt($this->httpConnection, CURLOPT_CUSTOMREQUEST, "POST");
98  curl_setopt($this->httpConnection, CURLOPT_RETURNTRANSFER, true);
99  }
+ Here is the caller graph for this function:

◆ connectUdp()

Monolog\Handler\CubeHandler::connectUdp ( )
protected

Establish a connection to an UDP socket.

Exceptions

Definition at line 65 of file CubeHandler.php.

Referenced by Monolog\Handler\CubeHandler\writeUdp().

66  {
67  if (!extension_loaded('sockets')) {
68  throw new MissingExtensionException('The sockets extension is required to use udp URLs with the CubeHandler');
69  }
70 
71  $this->udpConnection = socket_create(AF_INET, SOCK_DGRAM, 0);
72  if (!$this->udpConnection) {
73  throw new \LogicException('Unable to create a socket');
74  }
75 
76  if (!socket_connect($this->udpConnection, $this->host, $this->port)) {
77  throw new \LogicException('Unable to connect to the socket at ' . $this->host . ':' . $this->port);
78  }
79  }
+ Here is the caller graph for this function:

◆ write()

Monolog\Handler\CubeHandler::write ( array  $record)
protected

{}

Definition at line 104 of file CubeHandler.php.

References $data, array, Monolog\Handler\CubeHandler\writeHttp(), and Monolog\Handler\CubeHandler\writeUdp().

105  {
106  $date = $record['datetime'];
107 
108  $data = array('time' => $date->format('Y-m-d\TH:i:s.uO'));
109  unset($record['datetime']);
110 
111  if (isset($record['context']['type'])) {
112  $data['type'] = $record['context']['type'];
113  unset($record['context']['type']);
114  } else {
115  $data['type'] = $record['channel'];
116  }
117 
118  $data['data'] = $record['context'];
119  $data['data']['level'] = $record['level'];
120 
121  if ($this->scheme === 'http') {
122  $this->writeHttp(json_encode($data));
123  } else {
124  $this->writeUdp(json_encode($data));
125  }
126  }
Create styles array
The data for the language used.
+ Here is the call graph for this function:

◆ writeHttp()

Monolog\Handler\CubeHandler::writeHttp (   $data)
private

Definition at line 137 of file CubeHandler.php.

References $data, array, Monolog\Handler\CubeHandler\connectHttp(), and Monolog\Handler\Curl\Util\execute().

Referenced by Monolog\Handler\CubeHandler\write().

138  {
139  if (!$this->httpConnection) {
140  $this->connectHttp();
141  }
142 
143  curl_setopt($this->httpConnection, CURLOPT_POSTFIELDS, '['.$data.']');
144  curl_setopt($this->httpConnection, CURLOPT_HTTPHEADER, array(
145  'Content-Type: application/json',
146  'Content-Length: ' . strlen('['.$data.']'),
147  ));
148 
149  Curl\Util::execute($this->httpConnection, 5, false);
150  }
static execute($ch, $retries=5, $closeAfterDone=true)
Executes a CURL request with optional retries and exception on failure.
Definition: Util.php:32
connectHttp()
Establish a connection to a http server.
Definition: CubeHandler.php:85
Create styles array
The data for the language used.
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ writeUdp()

Monolog\Handler\CubeHandler::writeUdp (   $data)
private

Definition at line 128 of file CubeHandler.php.

References $data, and Monolog\Handler\CubeHandler\connectUdp().

Referenced by Monolog\Handler\CubeHandler\write().

129  {
130  if (!$this->udpConnection) {
131  $this->connectUdp();
132  }
133 
134  socket_send($this->udpConnection, $data, strlen($data), 0);
135  }
connectUdp()
Establish a connection to an UDP socket.
Definition: CubeHandler.php:65
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

Field Documentation

◆ $acceptedSchemes

Monolog\Handler\CubeHandler::$acceptedSchemes = array('http', 'udp')
private

Definition at line 29 of file CubeHandler.php.

◆ $host

Monolog\Handler\CubeHandler::$host
private

Definition at line 27 of file CubeHandler.php.

◆ $httpConnection

Monolog\Handler\CubeHandler::$httpConnection
private

Definition at line 25 of file CubeHandler.php.

◆ $port

Monolog\Handler\CubeHandler::$port
private

Definition at line 28 of file CubeHandler.php.

◆ $scheme

Monolog\Handler\CubeHandler::$scheme
private

Definition at line 26 of file CubeHandler.php.

◆ $udpConnection

Monolog\Handler\CubeHandler::$udpConnection
private

Definition at line 24 of file CubeHandler.php.


The documentation for this class was generated from the following file: