ILIAS  release_5-1 Revision 5.0.0-5477-g43f3e3fab5f
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 = null
 
 $httpConnection = null
 
 $scheme = null
 
 $host = null
 
 $port = null
 
 $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
UnexpectedValueExceptionwhen given url is not a valid url. A valid url must consists of three parts : protocol://host:port Only valid protocol used by Cube are http and udp

Definition at line 38 of file CubeHandler.php.

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

39  {
40  $urlInfos = parse_url($url);
41 
42  if (!isset($urlInfos['scheme']) || !isset($urlInfos['host']) || !isset($urlInfos['port'])) {
43  throw new \UnexpectedValueException('URL "'.$url.'" is not valid');
44  }
45 
46  if (!in_array($urlInfos['scheme'], $this->acceptedSchemes)) {
47  throw new \UnexpectedValueException(
48  'Invalid protocol (' . $urlInfos['scheme'] . ').'
49  . ' Valid options are ' . implode(', ', $this->acceptedSchemes));
50  }
51 
52  $this->scheme = $urlInfos['scheme'];
53  $this->host = $urlInfos['host'];
54  $this->port = $urlInfos['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.

Definition at line 83 of file CubeHandler.php.

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

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

◆ connectUdp()

Monolog\Handler\CubeHandler::connectUdp ( )
protected

Establish a connection to an UDP socket.

Exceptions
LogicExceptionwhen unable to connect to the socket

Definition at line 64 of file CubeHandler.php.

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

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

◆ write()

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

{}

Definition at line 102 of file CubeHandler.php.

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

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

◆ writeHttp()

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

Definition at line 135 of file CubeHandler.php.

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

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

136  {
137  if (!$this->httpConnection) {
138  $this->connectHttp();
139  }
140 
141  curl_setopt($this->httpConnection, CURLOPT_POSTFIELDS, '['.$data.']');
142  curl_setopt($this->httpConnection, CURLOPT_HTTPHEADER, array(
143  'Content-Type: application/json',
144  'Content-Length: ' . strlen('['.$data.']'))
145  );
146 
147  Curl\Util::execute($ch, 5, false);
148  }
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:83
$data
+ 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 126 of file CubeHandler.php.

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

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

127  {
128  if (!$this->udpConnection) {
129  $this->connectUdp();
130  }
131 
132  socket_send($this->udpConnection, $data, strlen($data), 0);
133  }
$data
connectUdp()
Establish a connection to an UDP socket.
Definition: CubeHandler.php:64
+ 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 = null
private

Definition at line 27 of file CubeHandler.php.

◆ $httpConnection

Monolog\Handler\CubeHandler::$httpConnection = null
private

Definition at line 25 of file CubeHandler.php.

◆ $port

Monolog\Handler\CubeHandler::$port = null
private

Definition at line 28 of file CubeHandler.php.

◆ $scheme

Monolog\Handler\CubeHandler::$scheme = null
private

Definition at line 26 of file CubeHandler.php.

◆ $udpConnection

Monolog\Handler\CubeHandler::$udpConnection = null
private

Definition at line 24 of file CubeHandler.php.


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