Add comment blocks
[civicrm-core.git] / CRM / Core / Error / Log.php
1 <?php
2
3 /*
4 +--------------------------------------------------------------------+
5 | CiviCRM version 4.7 |
6 +--------------------------------------------------------------------+
7 | Copyright CiviCRM LLC (c) 2004-2017 |
8 +--------------------------------------------------------------------+
9 | This file is a part of CiviCRM. |
10 | |
11 | CiviCRM is free software; you can copy, modify, and distribute it |
12 | under the terms of the GNU Affero General Public License |
13 | Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
14 | |
15 | CiviCRM is distributed in the hope that it will be useful, but |
16 | WITHOUT ANY WARRANTY; without even the implied warranty of |
17 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
18 | See the GNU Affero General Public License for more details. |
19 | |
20 | You should have received a copy of the GNU Affero General Public |
21 | License and the CiviCRM Licensing Exception along |
22 | with this program; if not, contact CiviCRM LLC |
23 | at info[AT]civicrm[DOT]org. If you have questions about the |
24 | GNU Affero General Public License or the licensing of CiviCRM, |
25 | see the CiviCRM license FAQ at http://civicrm.org/licensing |
26 +--------------------------------------------------------------------+
27 */
28
29 /**
30 * Class CRM_Core_Error_Log
31 *
32 * A PSR-3 wrapper for CRM_Core_Error.
33 */
34 class CRM_Core_Error_Log extends \Psr\Log\AbstractLogger {
35
36 /**
37 * CRM_Core_Error_Log constructor.
38 */
39 public function __construct() {
40 $this->map = array(
41 \Psr\Log\LogLevel::DEBUG => PEAR_LOG_DEBUG,
42 \Psr\Log\LogLevel::INFO => PEAR_LOG_INFO,
43 \Psr\Log\LogLevel::NOTICE => PEAR_LOG_NOTICE,
44 \Psr\Log\LogLevel::WARNING => PEAR_LOG_WARNING,
45 \Psr\Log\LogLevel::ERROR => PEAR_LOG_ERR,
46 \Psr\Log\LogLevel::CRITICAL => PEAR_LOG_CRIT,
47 \Psr\Log\LogLevel::ALERT => PEAR_LOG_ALERT,
48 \Psr\Log\LogLevel::EMERGENCY => PEAR_LOG_EMERG,
49 );
50 }
51
52 /**
53 * Logs with an arbitrary level.
54 *
55 * @param mixed $level
56 * @param string $message
57 * @param array $context
58 */
59 public function log($level, $message, array $context = array()) {
60 // FIXME: This flattens a $context a bit prematurely. When integrating
61 // with external/CMS logs, we should pass through $context.
62 if (!empty($context)) {
63 if (isset($context['exception'])) {
64 $context['exception'] = CRM_Core_Error::formatTextException($context['exception']);
65 }
66 $message .= "\n" . print_r($context, 1);
67 }
68 CRM_Core_Error::debug_log_message($message, FALSE, '', $this->map[$level]);
69 }
70
71 }