3 +--------------------------------------------------------------------+
4 | Copyright CiviCRM LLC. All rights reserved. |
6 | This work is published under the GNU AGPLv3 license with some |
7 | permitted exceptions and without any warranty. For full license |
8 | and copyright information, see https://civicrm.org/licensing |
9 +--------------------------------------------------------------------+
15 * @copyright CiviCRM LLC https://civicrm.org/licensing
17 class CRM_Utils_SystemLogger
extends Psr\Log\AbstractLogger
implements \Psr\Log\LoggerInterface
{
20 * Logs with an arbitrary level.
23 * @param string $message
24 * @param array $context
26 public function log($level, $message, array $context = []) {
27 if (!isset($context['hostname'])) {
28 $context['hostname'] = CRM_Utils_System
::ipAddress();
30 $rec = new CRM_Core_DAO_SystemLog();
31 $separateFields = ['contact_id', 'hostname'];
32 foreach ($separateFields as $separateField) {
33 if (isset($context[$separateField])) {
34 $rec->{$separateField} = $context[$separateField];
35 unset($context[$separateField]);
39 $rec->message
= $message;
40 $rec->context
= json_encode($context);