Logger   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 42
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 6
dl 0
loc 42
rs 10
c 0
b 0
f 0
wmc 3

3 Methods

Rating   Name   Duplication   Size   Complexity  
A warning() 0 3 1
A __construct() 0 4 1
A debug() 0 3 1
1
<?php
2
/*
3
 * This file is part of Rivescript-php
4
 *
5
 * (c) Shea Lewis <[email protected]>
6
 *
7
 * For the full copyright and license information, please view the LICENSE
8
 * file that was distributed with this source code.
9
 */
10
11
namespace Axiom\Rivescript\Support;
12
13
use Monolog\Logger as Monolog;
14
use Monolog\Handler\StreamHandler;
15
16
/**
17
 * Logger class
18
 *
19
 * This class is a wrapper around mono logger. It will
20
 * log entries to the log file.
21
 *
22
 * PHP version 7.4 and higher.
23
 *
24
 * @category Core
25
 * @package  Support
26
 * @author   Shea Lewis <[email protected]>
27
 * @license  https://opensource.org/licenses/MIT MIT
28
 * @link     https://github.com/axiom-labs/rivescript-php
29
 * @since    0.3.0
30
 */
31
class Logger
32
{
33
    /**
34
     * @var \Monolog\Logger
35
     */
36
    protected Monolog $logger;
37
38
    /**
39
     * Create a new Logger instance.
40
     *
41
     * @throws \Exception
42
     */
43
    public function __construct()
44
    {
45
        $this->logger = new Monolog('rivescript');
46
        $this->logger->pushHandler(new StreamHandler(__DIR__ . '/../../logs/' . date('m-d-y') . '.log', Monolog::DEBUG));
47
    }
48
49
    /**
50
     * Adds a log record at the DEBUG level.
51
     *
52
     * @param string  $message The log message
53
     * @param array[] $context The log context
54
     *
55
     * @return bool Whether the record has been processed
56
     */
57
    public function debug(string $message, array $context = []): bool
58
    {
59
        return $this->logger->addDebug($message, $context);
60
    }
61
62
    /**
63
     * Adds a log record at the WARNING level.
64
     *
65
     * @param string  $message The log message
66
     * @param array[] $context The log context
67
     *
68
     * @return bool Whether the record has been processed
69
     */
70
    public function warning(string $message, array $context = []): bool
71
    {
72
        return $this->logger->addWarning($message, $context);
73
    }
74
}
75