Issues (35)

Script/Security/Logger/Monolog.php (2 issues)

Labels
Severity
1
<?php
2
3
namespace Sludio\HelperBundle\Script\Security\Logger;
4
5
use Monolog\Handler\StreamHandler;
0 ignored issues
show
The type Monolog\Handler\StreamHandler 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...
6
use Monolog\Logger;
0 ignored issues
show
The type Monolog\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...
7
use Exception;
8
9
class Monolog
10
{
11
    public static function log($message, array $context = [], $type = 'info', $level = 0, $vendor = null)
12
    {
13
        if ($vendor === null) {
14
            $vendor = \defined('SLUDIO_HELPER') ? SLUDIO_HELPER : 'vendor';
15
        }
16
        self::getType($type);
17
18
        try {
19
            $log = self::registerLog($vendor);
20
            $debug = \debug_backtrace()[$level];
21
            $details = [
22
                $debug['file'],
23
                $debug['line'],
24
            ];
25
            $context = !empty($context) ? \array_merge($context, $details) : $details;
26
27
            $log->{strtolower($type)}($message, $context);
28
        } catch (Exception $exception) {
29
            return null;
30
        }
31
    }
32
33
    private static function getType(&$type)
34
    {
35
        if (!\array_key_exists(\strtoupper($type), Logger::getLevels())) {
36
            $type = Logger::getLevelName(Logger::INFO);
37
        }
38
    }
39
40
    /**
41
     * @param $vendor
42
     *
43
     * @return Logger
44
     * @throws Exception
45
     */
46
    private static function registerLog($vendor)
47
    {
48
        $log = new Logger($vendor);
49
        $directory = date('Y-m-j').'_vendor';
50
        $log->pushHandler(new StreamHandler(sprintf(getcwd().'/../var/logs/vendor/%s.log', $directory)));
51
52
        return $log;
53
    }
54
}
55