(NFC) (dev/core#878) Simplify copyright header (CRM/*)
[civicrm-core.git] / CRM / Core / Error / Log.php
CommitLineData
6e5ad5ee
TO
1<?php
2
3/*
4 +--------------------------------------------------------------------+
bc77d7c0 5 | Copyright CiviCRM LLC. All rights reserved. |
6e5ad5ee 6 | |
bc77d7c0
TO
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 |
6e5ad5ee
TO
10 +--------------------------------------------------------------------+
11 */
12
13/**
14 * Class CRM_Core_Error_Log
15 *
16 * A PSR-3 wrapper for CRM_Core_Error.
17 */
18class CRM_Core_Error_Log extends \Psr\Log\AbstractLogger {
19
8246bca4 20 /**
21 * CRM_Core_Error_Log constructor.
22 */
6e5ad5ee 23 public function __construct() {
be2fb01f 24 $this->map = [
6e5ad5ee
TO
25 \Psr\Log\LogLevel::DEBUG => PEAR_LOG_DEBUG,
26 \Psr\Log\LogLevel::INFO => PEAR_LOG_INFO,
27 \Psr\Log\LogLevel::NOTICE => PEAR_LOG_NOTICE,
28 \Psr\Log\LogLevel::WARNING => PEAR_LOG_WARNING,
29 \Psr\Log\LogLevel::ERROR => PEAR_LOG_ERR,
30 \Psr\Log\LogLevel::CRITICAL => PEAR_LOG_CRIT,
31 \Psr\Log\LogLevel::ALERT => PEAR_LOG_ALERT,
32 \Psr\Log\LogLevel::EMERGENCY => PEAR_LOG_EMERG,
be2fb01f 33 ];
6e5ad5ee
TO
34 }
35
36 /**
37 * Logs with an arbitrary level.
38 *
39 * @param mixed $level
40 * @param string $message
41 * @param array $context
42 */
be2fb01f 43 public function log($level, $message, array $context = []) {
6e5ad5ee
TO
44 // FIXME: This flattens a $context a bit prematurely. When integrating
45 // with external/CMS logs, we should pass through $context.
46 if (!empty($context)) {
47 if (isset($context['exception'])) {
48 $context['exception'] = CRM_Core_Error::formatTextException($context['exception']);
49 }
50 $message .= "\n" . print_r($context, 1);
6a59e510 51
52 if (CRM_Utils_System::isDevelopment() && CRM_Utils_Array::value('civi.tag', $context) === 'deprecated') {
53 trigger_error($message, E_USER_DEPRECATED);
54 }
6e5ad5ee 55 }
9726c118 56 CRM_Core_Error::debug_log_message($message, FALSE, '', $this->map[$level]);
6e5ad5ee
TO
57 }
58
59}