Passed
Pull Request — master (#2028)
by Gabriel
60:53
created

ErrbitLoggerFactory::createErrbitHandler()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 12
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 8
nc 1
nop 6
dl 0
loc 12
rs 10
c 1
b 0
f 0
1
<?php
2
declare( strict_types=1 );
3
4
namespace WMDE\Fundraising\Frontend\Factories;
5
6
use Airbrake\MonologHandler as AirbrakeHandler;
7
use Airbrake\Notifier;
8
use Monolog\Handler\ErrorLogHandler;
9
use Monolog\Handler\HandlerInterface;
10
use Monolog\Logger;
11
use Psr\Log\LogLevel;
12
use WMDE\Fundraising\Frontend\Infrastructure\SupportHandler;
13
14
class ErrbitLoggerFactory {
15
	public static function createErrbitHandler( string $projectId, string $projectKey, string $host, string $environment = 'dev', ?string $level = LogLevel::DEBUG, bool $bubble = true ): HandlerInterface {
16
		$notifier = new Notifier( [
17
			'projectId' => $projectId,
18
			'projectKey' => $projectKey,
19
			'host' => $host,
20
			'environment' => $environment
21
		] );
22
23
		// Wrap errbit handler in SupportHandler to avoid logception (logger trying to log logging errors) when errbit throws an error
24
		return new SupportHandler(
25
			new AirbrakeHandler( $notifier, Logger::toMonologLevel( $level ?? LogLevel::DEBUG ), $bubble ),
26
			new Logger( 'errbit errors', [ new ErrorLogHandler( ErrorLogHandler::OPERATING_SYSTEM, LogLevel::ERROR ), ] ),
27
		);
28
	}
29
30
}
31