ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
CouchDBHandler.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 
12 namespace Monolog\Handler;
13 
15 use Monolog\Logger;
16 
23 {
24  private $options;
25 
26  public function __construct(array $options = array(), $level = Logger::DEBUG, $bubble = true)
27  {
28  $this->options = array_merge(array(
29  'host' => 'localhost',
30  'port' => 5984,
31  'dbname' => 'logger',
32  'username' => null,
33  'password' => null,
34  ), $options);
35 
36  parent::__construct($level, $bubble);
37  }
38 
42  protected function write(array $record)
43  {
44  $basicAuth = null;
45  if ($this->options['username']) {
46  $basicAuth = sprintf('%s:%s@', $this->options['username'], $this->options['password']);
47  }
48 
49  $url = 'http://'.$basicAuth.$this->options['host'].':'.$this->options['port'].'/'.$this->options['dbname'];
50  $context = stream_context_create(array(
51  'http' => array(
52  'method' => 'POST',
53  'content' => $record['formatted'],
54  'ignore_errors' => true,
55  'max_redirects' => 0,
56  'header' => 'Content-type: application/json',
57  ),
58  ));
59 
60  if (false === @file_get_contents($url, null, $context)) {
61  throw new \RuntimeException(sprintf('Could not connect to %s', $url));
62  }
63  }
64 
68  protected function getDefaultFormatter()
69  {
71  }
72 }
const DEBUG
Detailed debug information.
Definition: Logger.php:32
Base Handler class providing the Handler structure.
Create styles array
The data for the language used.
Encodes whatever record data is passed to it as json.
$url
__construct(array $options=array(), $level=Logger::DEBUG, $bubble=true)