@@ -244,4 +244,72 @@ Also, update the resource configuration in `./resources/auditLogs.ts`:
244244 }),
245245 ],
246246 }
247+ ` ` `
248+ ## Logging client ip country
249+
250+ Audit log can also log the client's country if needed.
251+
252+ Also, you need to migrate the ` audit_logs ` table in ` ./ schema .prisma ` :
253+
254+ ` ` ` ts title = ' ./schema.prisma'
255+ model audit_logs {
256+ id String @id
257+ created_at DateTime // / timestamp of applied change
258+ resource_id String // / identifier of resource where change were applied
259+ user_id String // / identifier of user who made the changes
260+ action String // / type of change (create, edit, delete)
261+ diff String? // / delta betwen before/after versions
262+ record_id String? // / identifier of record that been changed
263+ ip_address String? // / client ip address
264+ // diff-add
265+ country String? // / client country
266+
267+ // diff-add
268+ @@index([ip_address ]) // / index for fast lookups by IP
269+ }
270+ ` ` `
271+
272+ And ` prisma migrate ` :
273+
274+ ` ` ` bash
275+ npm run makemigration -- -- name add - ip - address - to - audit - logs ; npm run migrate : local
276+ ` ` `
277+
278+ Update the resource configuration in ` ./ resources / auditLogs .ts ` :
279+
280+ ` ` ` ts title = ' ./resources/auditLogs.ts'
281+ export default {
282+ dataSource: ' maindb' ,
283+ table: ' audit_logs' ,
284+ columns: [
285+ ...
286+ { name: ' action' , required: false },
287+ { name: ' diff' , required: false , type: AdminForthDataTypes .JSON , showIn: {
288+ list: false ,
289+ edit: false ,
290+ create: false ,
291+ filter: false ,
292+ } },
293+ { name: ' record_id' , required: false },
294+ { name: ' ip_address' , required: false },
295+ // diff-add
296+ { name: " country" , required: false },
297+ ],
298+ ...
299+ plugins : [
300+ new AuditLogPlugin ({
301+ resourceColumns: {
302+ resourceIdColumnName: ' resource_id' ,
303+ resourceActionColumnName: ' action' ,
304+ resourceDataColumnName: ' diff' ,
305+ resourceUserIdColumnName: ' user_id' ,
306+ resourceRecordIdColumnName: ' record_id' ,
307+ resourceCreatedColumnName: ' created_at'
308+ resourceIpColumnName : " ip_address" ,
309+ // diff-add
310+ resourceCountryColumnName: " country" ,
311+ }
312+ }),
313+ ],
314+ }
247315` ` `
0 commit comments