private function log($message, $objects) { // in php, both arrays and objects can have key->val // in json, arrays cannot have key->val // this'll change the interior "arrays" from the "response" which appear in json as objects, into objects $objects = json_encode($objects); $objects = json_decode($objects); // prevent logging of passwords // if (property_exists($objects, "data") && property_exists($objects->data, "password")) { if (isset($objects->data) && isset($objects->data->password)) { $objects->data->password = '******'; } if (is_array($objects)) { $tidyObjects = array(); foreach ($objects as $object) { $tidyObjects[] = $this->tidyObject($object); } } else { $tidyObjects = $this->tidyObject($objects); } $output = json_encode($tidyObjects); // record the user's last activity $userName = "******"; if (isset($_SERVER['REMOTE_ADDR'])) { $userName = $_SERVER['REMOTE_ADDR']; } if (isset($_SERVER['HTTP_X_FORWARDED_FOR'])) { $userName = $_SERVER['HTTP_X_FORWARDED_FOR']; } if ($currentUser = $this->plugin->Auth->getUserID()) { $model = $this->plugin->MvcQuery->getModel('User'); $results = $model->read(array('id' => $currentUser)); if (sizeof($results)) { $user = $results[0]; $userName = $user['email']; } } \application\helper\DebugHelper::logToFile('api.log', "{$userName} {$message} {$output}"); }