Mhmod-Hsn

payload audit logs

by Mhmod-Hsn
Logging & monitoring
v3
^3.82.1
MIT

Overview

Summary generated from the README

Adds an Audit Logs collection to Payload and records operations on the collections you select. Each entry stores the entity, document ID, operation, the acting user, and the original and new data as JSON. Configured through the plugins array, with options for access control, hiding the collection from navigation, and the user collection slug. Requires Payload 3.

Features

  • Tracks create, read, update and delete operations per collection
  • Stores original and new data as JSON for each change
  • Links each log entry to the user who performed the operation
  • Configurable access rules for the generated Audit Logs collection
  • Option to hide the Audit Logs collection from the sidebar
  • Can be disabled per environment with a flag

Use cases

  • Record who changed or deleted content in sensitive collections for compliance review
  • Keep a history of before and after values for edits to settings or user documents

From the author

Audit log plugin for Payload CMS

Installation

npm i payload-audit-logs

6

Stars

0

Forks

0

Open Issues

4 months ago

Last Updated

0

Weekly Downloads

v1.2.0

npm Version

56.1 KB

Unpacked Size

0

Dependencies

GitHub stars

Trends appear after 7 days of data. Daily snapshots have not started yet.

npm weekly downloads

Trends appear after 7 days of data. Daily snapshots have not started yet.

Each point is npm's rolling 7-day download count.

Health Score

50/100Good

Composite score based on GitHub activity, stars, npm downloads, publish recency, dependency count, and package size.

Badge for your README

Payload Directory health badge
Markdown
[![Payload Directory](https://payloaddirectory.dev/badge/1216292583-root.svg)](https://payloaddirectory.dev/plugins/1216292583-root)
HTML
<a href="https://payloaddirectory.dev/plugins/1216292583-root"><img src="https://payloaddirectory.dev/badge/1216292583-root.svg" alt="Payload Directory"></a>
Updated Jun 8, 2026Created Apr 20, 2026Published Jun 8, 2026

README

Payload Audit Logs

A Payload CMS plugin to automatically track and log CRUD operations (Create, Read, Update, Delete) on specified collections.

Features

  • Automatic Logging: Automatically creates audit logs for create, read, update, and delete operations.
  • Configurable: Choose which collections and which operations to track.
  • Historical Data: Stores both the originalData (before change) and newData (after change) for full auditability.
  • User Association: Automatically links logs to the user who performed the operation.
  • Easy Integration: Simple setup in your Payload configuration.

Installation

pnpm add payload-audit-logs
# or
npm install payload-audit-logs
# or
yarn add payload-audit-logs

Usage

Add the plugin to your Payload configuration:

import { buildConfig } from 'payload'
import { auditLogPlugin } from 'payload-audit-logs'

export default buildConfig({
  plugins: [
    auditLogPlugin({
      collections: {
        posts: {
          operations: ['create', 'update', 'delete'],
        },
        users: {
          operations: ['create', 'update', 'delete'],
        },
        media: {
          operations: ['create', 'update', 'delete'],
        },
      },
      userCollection: 'users', // Optional, defaults to 'users'
    }),
  ],
  // ... rest of your config
})

Configuration

The plugin accepts the following options:

OptionTypeDefaultDescription
collectionsRecord<string, { operations: string[] }>{}A map of collection slugs to track and the operations to log for each.
disabledbooleanfalseIf true, the plugin will be disabled.
userCollectionstring'users'The slug of the collection used for users.
auditLogsAccessCollectionConfig['access']{ ... }Access control functions for the generated Audit Logs collection.
hideAuditLogsboolean | ((args: { user: PayloadRequest['user'] | null }) => boolean)falseHide the Audit Logs collection from the sidebar navigation.

Operations

You can specify which operations to log for each collection:

  • create: Logs when a new document is created.
  • read: Logs when a document is retrieved.
  • update: Logs when an existing document is modified.
  • delete: Logs when a document is removed.

CAUTION: Enabling the read operation can significantly increase database storage consumption and create redundant logs, especially for high-traffic collections. Use it sparingly and only when strictly necessary for auditing sensitive information.

Code Sample

import { buildConfig } from 'payload'
import { auditLogPlugin } from 'payload-audit-logs'

export default buildConfig({
  plugins: [
    auditLogPlugin({
      // Track specific collections
      collections: {
        posts: {
          operations: ['create', 'update', 'delete'],
        },
        // Sensitive data might require 'read' logging
        settings: {
          operations: ['read', 'update'],
        },
      },
      // Configure user collection if it's not 'users'
      userCollection: 'admins',
      // Useful for environment-specific disabling
      disabled: process.env.NODE_ENV === 'test',
    }),
  ],
})

Audit Logs Collection

When the plugin is enabled, it automatically adds an Audit Logs collection to your Payload admin panel.

Fields

  • Entity: The slug of the collection where the operation occurred.
  • Document ID: The ID of the affected document.
  • Operation: The type of operation performed (create, read, update, or delete).
  • User: A relationship to the user who performed the operation.
  • Original Data: (JSON) The data before the change occurred (available for update and delete).
  • New Data: (JSON) The data after the change occurred (available for create, read, and update).
  • Created At: Timestamp of when the log entry was created.

Access Control

By default:

  • Create/Update/Delete: Restricted (only the plugin can create logs).
  • Read: Any authenticated user can view audit logs.

You can fully customize these rules by providing the auditLogsAccess property in your plugin configuration.

Development

If you want to contribute or modify the plugin:

  1. Clone the repository.
  2. Install dependencies: pnpm install.
  3. Start the dev project: pnpm dev.
  4. Run tests: pnpm test.

License

MIT

Similar plugins