def audit_log(action, request_user, account_user, message, audit, request, level=logging.DEBUG): """ Create a log message based on these params @param action: Action performed e.g. form-deleted @param request_username: User performing the action @param account_username: The formhub account the action was performed on @param message: The message to be displayed on the log @param level: log level @param audit: a dict of key/values of other info pertaining to the action e.g. form's id_string, submission uuid @return: None """ logger = logging.getLogger("audit_logger") extra = { 'formhub_action': action, 'request_username': request_user.username if request_user.username else str(request_user), 'account_username': account_user.username if account_user.username else str(account_user), 'client_ip': get_client_ip(request), 'audit': audit } logger.log(level, message, extra=extra)
def test_get_client_ip(self): request = RequestFactory().get("/") client_ip = get_client_ip(request) self.assertIsNotNone(client_ip) # will this always be 127.0.0.1 self.assertEqual(client_ip, "127.0.0.1")