LogsToFile::log()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 7
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 3
c 1
b 0
f 0
dl 0
loc 7
rs 10
cc 2
nc 2
nop 3
1
<?php
2
3
/*
4
 * This file is part of the PHALCON-EXT package.
5
 *
6
 * (c) Jitendra Adhikari <[email protected]>
7
 *     <https://github.com/adhocore>
8
 *
9
 * Licensed under MIT license.
10
 */
11
12
namespace PhalconExt\Logger;
13
14
use Phalcon\Di;
0 ignored issues
show
Bug introduced by
The type Phalcon\Di was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
15
use Phalcon\Logger;
0 ignored issues
show
Bug introduced by
The type Phalcon\Logger was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
16
use Phalcon\Logger\Adapter\File as FileLogger;
0 ignored issues
show
Bug introduced by
The type Phalcon\Logger\Adapter\File was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
17
use Phalcon\Logger\Formatter\Line as LineFormatter;
0 ignored issues
show
Bug introduced by
The type Phalcon\Logger\Formatter\Line was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
18
19
/**
20
 * Provides di service.
21
 *
22
 * @author  Jitendra Adhikari <[email protected]>
23
 * @license MIT
24
 *
25
 * @link    https://github.com/adhocore/phalcon-ext
26
 */
27
trait LogsToFile
28
{
29
    /** @var bool */
30
    protected $activated = false;
31
32
    /** @var FileLogger */
33
    protected $logger;
34
35
    /**
36
     * Log the given message and level. Interpolates message if applicable from context.
37
     *
38
     * @param string $message
39
     * @param int    $level
40
     * @param array  $context
41
     *
42
     * @return void
43
     */
44
    public function log(string $message, int $level = Logger::DEBUG, array $context = [])
45
    {
46
        if (!$this->activated) {
47
            return;
48
        }
49
50
        $this->logger->log($message, $level, $context);
51
    }
52
53
    /**
54
     * Activate the logger.
55
     *
56
     * @param string $logPath
57
     *
58
     * @return void
59
     */
60
    protected function activate(string $logPath)
61
    {
62
        $logPath = \rtrim($logPath, '/\\') . '/';
63
64
        $this->activated = true;
65
        $this->logger    = new FileLogger($logPath . \date('Y-m-d') . $this->fileExtension);
66
67
        $this->logger->setFormatter(new LineFormatter($this->logFormat ?? null));
68
    }
69
}
70