Version: 4.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 "@refinedev/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 "@refinedev/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β
Property | Type |
---|---|
resource Required | string |
action Required | string |
author | Record<string, any> |
meta | Record<string, any> |
data | Record<string, any> |
previousData | Record<string, any> |
Type Parametersβ
Property | Desription | Type | Default |
---|---|---|---|
TData | Result data of the mutation. Extends BaseRecord | BaseRecord | BaseRecord |
TError | Custom error object that extends HttpError | HttpError | HttpError |
TVariables | Values for mutation function | {} | {} |
Return valueβ
Description | Type |
---|---|
Result of the react-query 's useMutation | UseMutationResult< { 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 "@refinedev/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β
Property | Type |
---|---|
id Required | BaseKey |
name Required | string |
Type Parametersβ
Property | Desription | Type | Default |
---|---|---|---|
TData | Result data of the mutation. Extends BaseRecord | BaseRecord | BaseRecord |
TError | Custom error object that extends HttpError | HttpError | HttpError |
TVariables | Values for mutation function | {} | {} |
Return valueβ
Description | Type |
---|---|
Result of the react-query 's useMutation | UseMutationResult< { data: TData}, TError, { id: BaseKey; name: string; }, unknown> |
info
You can get audit logs with useLogList
.