Merge pull request #16626 from pradpnayak/lineItemFixes
[civicrm-core.git] / CRM / Core / Error / Log.php
1 <?php
2
3 /*
4 +--------------------------------------------------------------------+
5 | Copyright CiviCRM LLC. All rights reserved. |
6 | |
7 | This work is published under the GNU AGPLv3 license with some |
8 | permitted exceptions and without any warranty. For full license |
9 | and copyright information, see https://civicrm.org/licensing |
10 +--------------------------------------------------------------------+
11 */
12
13 /**
14 * Class CRM_Core_Error_Log
15 *
16 * A PSR-3 wrapper for CRM_Core_Error.
17 */
18 class CRM_Core_Error_Log extends \Psr\Log\AbstractLogger {
19
20 /**
21 * @var array
22 */
23 public $map;
24
25 /**
26 * CRM_Core_Error_Log constructor.
27 */
28 public function __construct() {
29 $this->map = [
30 \Psr\Log\LogLevel::DEBUG => PEAR_LOG_DEBUG,
31 \Psr\Log\LogLevel::INFO => PEAR_LOG_INFO,
32 \Psr\Log\LogLevel::NOTICE => PEAR_LOG_NOTICE,
33 \Psr\Log\LogLevel::WARNING => PEAR_LOG_WARNING,
34 \Psr\Log\LogLevel::ERROR => PEAR_LOG_ERR,
35 \Psr\Log\LogLevel::CRITICAL => PEAR_LOG_CRIT,
36 \Psr\Log\LogLevel::ALERT => PEAR_LOG_ALERT,
37 \Psr\Log\LogLevel::EMERGENCY => PEAR_LOG_EMERG,
38 ];
39 }
40
41 /**
42 * Logs with an arbitrary level.
43 *
44 * @param mixed $level
45 * @param string $message
46 * @param array $context
47 */
48 public function log($level, $message, array $context = []) {
49 // FIXME: This flattens a $context a bit prematurely. When integrating
50 // with external/CMS logs, we should pass through $context.
51 if (!empty($context)) {
52 if (isset($context['exception'])) {
53 $context['exception'] = CRM_Core_Error::formatTextException($context['exception']);
54 }
55 $message .= "\n" . print_r($context, 1);
56
57 if (CRM_Utils_System::isDevelopment() && CRM_Utils_Array::value('civi.tag', $context) === 'deprecated') {
58 trigger_error($message, E_USER_DEPRECATED);
59 }
60 }
61 CRM_Core_Error::debug_log_message($message, FALSE, '', $this->map[$level]);
62 }
63
64 }