CouchHandler   A
last analyzed

Complexity

Total Complexity 10

Size/Duplication

Total Lines 56
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 10
c 1
b 0
f 0
lcom 1
cbo 2
dl 0
loc 56
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
D write() 0 36 9
1
<?php
2
3
/**
4
 * @file CouchHandler.php
5
 * @brief This file contains the CouchHandler class.
6
 * @details
7
 * @author Filippo F. Fadda
8
 */
9
10
11
//! This namespace contains the error handler.
12
namespace EoC\Handler;
13
14
15
use Monolog\Logger;
16
use Monolog\Handler\AbstractProcessingHandler;
17
18
use EoC\Server;
19
20
21
/*
22
 * @brief This special handler writes logging messages directly into the `couch.log` file.
23
 * @details It doesn't handle debug messages, because this handler is always pushed to the logger. This handler logs
24
 * info messages and errors.
25
 */
26
class CouchHandler extends AbstractProcessingHandler {
27
  private $server;
28
29
30
  /**
31
   * @brief Constructor.
32
   * @param[in] Server $server The ElephantOnCouch Query Server instance.
33
   */
34
  public function __construct(Server $server) {
35
    $this->server = $server;
36
    parent::__construct(Logger::INFO, TRUE);
37
  }
38
39
40
  /**
41
   * @brief Writes the record down to the log of the implementing handler
42
   * @param[in] array $record The log record to be written.
43
   */
44
  protected function write(array $record) {
45
46
    switch ($record['level']) {
47
      case Logger::DEBUG: // Ignores it.
48
        break;
49
50
      case Logger::INFO: // Sends a message.
51
        $this->server->log($record['message']);
52
        break;
53
54
      case Logger::NOTICE: // Sends a message.
55
        $this->server->log($record['message']);
56
        break;
57
58
      case Logger::WARNING: // Sends a message.
59
        $this->server->log($record['message']);
60
        break;
61
62
      case Logger::ERROR:
63
        $this->server->error($record['channel'], $record['message']);
64
        break;
65
66
      case Logger::CRITICAL:
67
        $this->server->error($record['channel'], $record['message']);
68
        break;
69
70
      case Logger::ALERT:
71
        $this->server->error($record['channel'], $record['message']);
72
        break;
73
74
      case Logger::EMERGENCY:
75
        $this->server->error($record['channel'], $record['message']);
76
        break;
77
    }
78
79
  }
80
81
}