Logger::log()   A
last analyzed

Complexity

Conditions 4
Paths 3

Size

Total Lines 13
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 13
rs 9.2
cc 4
eloc 6
nc 3
nop 2
1
<?php
2
/**
3
 * Logger.php
4
 *
5
 * @copyright      More in license.md
6
 * @license        https://www.ipublikuj.eu
7
 * @author         Adam Kadlec <[email protected]>
8
 * @package        iPublikuj:Framework!
9
 * @subpackage     Loggers
10
 * @since          1.0.0
11
 *
12
 * @date           12.03.14
13
 */
14
15
declare(strict_types = 1);
16
17
namespace IPub\NewRelic\Loggers;
18
19
use Tracy;
20
21
/**
22
 * Error logger
23
 *
24
 * @package        iPublikuj:NewRelic!
25
 * @subpackage     Loggers
26
 *
27
 * @author         Adam Kadlec <[email protected]>
28
 */
29
final class Logger extends Tracy\Logger
30
{
31
	/**
32
	 * Logs message or exception to file and sends email notification.
33
	 *
34
	 * @param string|array $message
35
	 * @param int $priority one of constant self::INFO, WARNING, ERROR (sends email), EXCEPTION (sends email), CRITICAL (sends email)
36
	 *
37
	 * @return void
38
	 */
39
	public function log($message, $priority = self::INFO) : void
40
	{
41
		parent::log($message, $priority);
42
43
		// Log only errors
44
		if ($priority === self::ERROR || $priority === self::CRITICAL) {
45
			if (is_array($message)) {
46
				$message = implode(' ', $message);
47
			}
48
49
			newrelic_notice_error($message);
50
		}
51
	}
52
}
53