Skip to main content
Refine AI
Version: 3.xx.xx

useLog

Overview

If you need to create or update an audit log, refine provides the useLog hook for it. The hook returns two mutations called log and rename.

import { useLog } from "@pankod/refine-core";

const { log, rename } = useLog();

log

log is used to create an audit log event. The mutation uses create method from auditLogProvider under the hood.

import { useLog } from "@pankod/refine-core";

const { log } = useLog();
const { mutate } = log;

mutate({
resource: "posts",
action: "create",
author: {
username: "admin",
},
data: {
id: 1,
title: "New post",
},
meta: {
id: 1,
},
});
CAUTION

This hook can only be used if auditLogProvider's create method is provided.

Properties

PropertyType
resource
Required
string
action
Required
string
authorRecord<string, any>
metaRecord<string, any>
dataRecord<string, any>
previousDataRecord<string, any>

Type Parameters

PropertyDesriptionTypeDefault
TDataResult data of the mutation. Extends BaseRecordBaseRecordBaseRecord
TErrorCustom error object that extends HttpErrorHttpErrorHttpError
TVariablesValues for mutation function{}{}

Return value

DescriptionType
Result of the react-query's useMutationUseMutationResult<
{ data: TData},
TError,
{ id: BaseKey; name: string; },
unknown>

rename

log is used to update an audit log event. The mutation uses update method from auditLogProvider under the hood.

import { useLog } from "@pankod/refine-core";

const { rename } = useLog();
const { mutate } = rename;

mutate({
id: 1,
name: "Updated Name",
});
CAUTION

This hook can only be used if auditLogProvider's update method is provided.

Properties

PropertyType
id
Required
BaseKey
name
Required
string

Type Parameters

PropertyDesriptionTypeDefault
TDataResult data of the mutation. Extends BaseRecordBaseRecordBaseRecord
TErrorCustom error object that extends HttpErrorHttpErrorHttpError
TVariablesValues for mutation function{}{}

Return value

DescriptionType
Result of the react-query's useMutationUseMutationResult<
{ data: TData},
TError,
{ id: BaseKey; name: string; },
unknown>

INFORMATION

You can get audit logs with useLogList.