X-Git-Url: https://vcs.fsf.org/?a=blobdiff_plain;f=api%2Fv3%2FSystem.php;h=79c66f264578aa539992a62d01dbf1bbe2e35cda;hb=85bb0909cffd925f4cd5c0022a68a1ff74d3ad8e;hp=1c7875d58875b73d1037bf6849ba8eb89fed8aee;hpb=68d6b897b10ec82e276280d07d9614c79561639d;p=civicrm-core.git diff --git a/api/v3/System.php b/api/v3/System.php index 1c7875d588..79c66f2645 100644 --- a/api/v3/System.php +++ b/api/v3/System.php @@ -98,4 +98,61 @@ function civicrm_api3_system_check($params) { // Spec: civicrm_api3_create_success($values = 1, $params = array(), $entity = NULL, $action = NULL) return civicrm_api3_create_success($returnValues, $params, 'System', 'Check'); -} \ No newline at end of file +} + +/** + * @param $params + * + * @return array + */ +function civicrm_api3_system_log($params) { + $log = new CRM_Utils_SystemLogger(); + // this part means fields with separate db storage are accepted as params which kind of seems more intuitive to me + // because I felt like not doing this required a bunch of explanation in the spec function - but perhaps other won't see it as helpful? + if(!isset($params['context'])) { + $params['context'] = array(); + } + $specialFields = array('contact_id', 'hostname'); + foreach($specialFields as $specialField) { + if(isset($params[$specialField]) && !isset($params['context'])) { + $params['context'][$specialField] = $params[$specialField]; + } + } + $returnValues = $log->log($params['level'], $params['message'], $params['context']); + return civicrm_api3_create_success($returnValues, $params, 'System', 'Log'); +} + +/** + * Metadata for log function + * @param $params + */ +function _civicrm_api3_system_log_spec(&$params) { + $params['level'] = array( + 'title' => 'Log Level', + 'description' => 'Log level as described in PSR3 (info, debug, warning etc)', + 'type' => CRM_Utils_Type::T_STRING, + 'api.required' => TRUE, + ); + $params['message'] = array( + 'title' => 'Log Message', + 'description' => 'Standardised message string, you can also ', + 'type' => CRM_Utils_Type::T_STRING, + 'api.required' => TRUE, + ); + $params['context'] = array( + 'title' => 'Log Context', + 'description' => 'An array of additional data to store.', + 'type' => CRM_Utils_Type::T_LONGTEXT, + 'api.default' => array(), + ); + $params['contact_id'] = array( + 'title' => 'Log Contact ID', + 'description' => 'Optional ID of relevant contact', + 'type' => CRM_Utils_Type::T_INT, + ); + $params['hostname'] = array( + 'title' => 'Log Hostname', + 'description' => 'Optional name of host', + 'type' => CRM_Utils_Type::T_STRING, + ); +}