| 1 | <?php |
| 2 | /* |
| 3 | +--------------------------------------------------------------------+ |
| 4 | | Copyright CiviCRM LLC. All rights reserved. | |
| 5 | | | |
| 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 | +--------------------------------------------------------------------+ |
| 10 | */ |
| 11 | |
| 12 | /** |
| 13 | * |
| 14 | * @package CRM |
| 15 | * @copyright CiviCRM LLC https://civicrm.org/licensing |
| 16 | */ |
| 17 | class CRM_Utils_SystemLogger extends Psr\Log\AbstractLogger implements \Psr\Log\LoggerInterface { |
| 18 | |
| 19 | /** |
| 20 | * Logs with an arbitrary level. |
| 21 | * |
| 22 | * @param mixed $level |
| 23 | * @param string $message |
| 24 | * @param array $context |
| 25 | */ |
| 26 | public function log($level, $message, array $context = []) { |
| 27 | if (!isset($context['hostname'])) { |
| 28 | $context['hostname'] = CRM_Utils_System::ipAddress(); |
| 29 | } |
| 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]); |
| 36 | } |
| 37 | } |
| 38 | $rec->level = $level; |
| 39 | $rec->message = $message; |
| 40 | $rec->context = json_encode($context); |
| 41 | $rec->save(); |
| 42 | } |
| 43 | |
| 44 | } |