1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace Canvas\Providers; |
6
|
|
|
|
7
|
|
|
use function Canvas\Core\appPath; |
8
|
|
|
use function Canvas\Core\envValue; |
9
|
|
|
use Monolog\Formatter\LineFormatter; |
10
|
|
|
use Monolog\Handler\StreamHandler; |
11
|
|
|
use Monolog\Logger; |
12
|
|
|
use Phalcon\Di\ServiceProviderInterface; |
|
|
|
|
13
|
|
|
use Phalcon\DiInterface; |
|
|
|
|
14
|
|
|
use Raven_Client; |
15
|
|
|
use Monolog\Handler\RavenHandler; |
16
|
|
|
|
17
|
|
|
class LoggerProvider implements ServiceProviderInterface |
18
|
|
|
{ |
19
|
|
|
/** |
20
|
|
|
* Registers the logger component. |
21
|
|
|
* |
22
|
|
|
* @param DiInterface $container |
23
|
|
|
*/ |
24
|
4 |
|
public function register(DiInterface $container) |
25
|
|
|
{ |
26
|
4 |
|
$config = $container->getShared('config'); |
27
|
|
|
|
28
|
4 |
|
$container->setShared( |
29
|
4 |
|
'log', |
30
|
4 |
|
function () use ($config) { |
31
|
|
|
/** @var string $logName */ |
32
|
4 |
|
$logName = envValue('LOGGER_DEFAULT_FILENAME', 'api.log'); |
33
|
|
|
/** @var string $logPath */ |
34
|
4 |
|
$logPath = envValue('LOGGER_DEFAULT_PATH', 'storage/logs'); |
35
|
4 |
|
$logFile = appPath($logPath) . '/' . $logName . '.log'; |
36
|
|
|
|
37
|
4 |
|
$formatter = new LineFormatter("[%datetime%][%level_name%] %message% %context% \n"); |
38
|
|
|
|
39
|
4 |
|
$logger = new Logger('api-logger'); |
40
|
|
|
|
41
|
4 |
|
$handler = new StreamHandler($logFile, Logger::DEBUG); |
42
|
4 |
|
$handler->setFormatter($formatter); |
43
|
|
|
|
44
|
|
|
//only run logs in production |
45
|
4 |
|
if ($config->app->logsReport) { |
46
|
|
|
//sentry logger |
47
|
|
|
$client = new Raven_Client('https://' . getenv('SENTRY_RPOJECT_SECRET') . '@sentry.io/' . getenv('SENTRY_PROJECT_ID')); |
48
|
|
|
$handlerSentry = new RavenHandler($client, Logger::ERROR); |
49
|
|
|
$handlerSentry->setFormatter(new LineFormatter("%message% %context% %extra%\n")); |
50
|
|
|
$logger->pushHandler($handlerSentry); |
51
|
|
|
} |
52
|
|
|
|
53
|
4 |
|
$logger->pushHandler($handler); |
54
|
|
|
|
55
|
4 |
|
return $logger; |
56
|
4 |
|
} |
57
|
|
|
); |
58
|
4 |
|
} |
59
|
|
|
} |
60
|
|
|
|
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:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths