ILIAS  release_5-1 Revision 5.0.0-5477-g43f3e3fab5f
AmqpHandler.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
16use PhpAmqpLib\Message\AMQPMessage;
17use PhpAmqpLib\Channel\AMQPChannel;
18use AMQPExchange;
19
21{
25 protected $exchange;
26
30 protected $exchangeName;
31
38 public function __construct($exchange, $exchangeName = 'log', $level = Logger::DEBUG, $bubble = true)
39 {
40 if ($exchange instanceof AMQPExchange) {
41 $exchange->setName($exchangeName);
42 } elseif ($exchange instanceof AMQPChannel) {
43 $this->exchangeName = $exchangeName;
44 } else {
45 throw new \InvalidArgumentException('PhpAmqpLib\Channel\AMQPChannel or AMQPExchange instance required');
46 }
47 $this->exchange = $exchange;
48
49 parent::__construct($level, $bubble);
50 }
51
55 protected function write(array $record)
56 {
57 $data = $record["formatted"];
58
59 $routingKey = sprintf(
60 '%s.%s',
61 // TODO 2.0 remove substr call
62 substr($record['level_name'], 0, 4),
63 $record['channel']
64 );
65
66 if ($this->exchange instanceof AMQPExchange) {
67 $this->exchange->publish(
68 $data,
69 strtolower($routingKey),
70 0,
71 array(
72 'delivery_mode' => 2,
73 'Content-type' => 'application/json'
74 )
75 );
76 } else {
77 $this->exchange->basic_publish(
78 new AMQPMessage(
79 (string) $data,
80 array(
81 'delivery_mode' => 2,
82 'content_type' => 'application/json'
83 )
84 ),
85 $this->exchangeName,
86 strtolower($routingKey)
87 );
88 }
89 }
90
94 protected function getDefaultFormatter()
95 {
97 }
98}
Encodes whatever record data is passed to it as json.
Base Handler class providing the Handler structure.
write(array $record)
Writes the record down to the log of the implementing handler.void
Definition: AmqpHandler.php:55
__construct($exchange, $exchangeName='log', $level=Logger::DEBUG, $bubble=true)
Definition: AmqpHandler.php:38
getDefaultFormatter()
Gets the default formatter.FormatterInterface
Definition: AmqpHandler.php:94
Monolog log channel.
Definition: Logger.php:28
const DEBUG
Detailed debug information.
Definition: Logger.php:32
$data