Skip to content
KeystoneJS LogoKeystoneJS
👋🏻 Keystone 5 has officially moved to maintenance only. For the latest release of Keystone please visit the Keystone website.

logging Plugin

This plugin provides a mechanism for logging all mutations in a Keystone system.

Usage

JS
const { logging } = require('@keystonejs/list-plugins');

keystone.createList('ListWithPlugin', {
  fields: {...},
  plugins: [
    logging(args => console.log(args)),
  ],
});

keystone.createAuthStrategy({
  type: PasswordAuthStrategy,
  list: 'User',
  plugins: [
    logging(args => console.log(args)),
  ]
})

Provided hooks

The logging plugin will log the arguments of all mutations with the function args => console.log(JSON.stringify(args)). You can customise its behaviour by providing an alternate logging function.

The plugin provides the following hooks:

  • afterChange
  • afterDelete
  • afterAuth
  • afterUnauth

The logging function for each hook recieves specific arguments related to the mutation.

afterChange (create)

OptionTypeDescription
operationString"create"
authedItemObjectThe currently authenticated item.
authedListKeyStringThe list currently authenticated against.
listKeyStringThe key of the list being operated on.
originalInputObjectThe original input to the mutation.
createdItemObjectThe database record of the created item.

afterChange (update)

OptionTypeDescription
operationString"update"
authedItemObjectThe currently authenticated item.
authedListKeyStringThe list currently authenticated against.
listKeyStringThe key of the list being operated on.
originalInputObjectThe original input to the mutation.
changedItemObjectThe database record of the updated item. This will only include those fields which have actually been changed.

afterDelete

OptionTypeDescription
operationString"delete"
authedItemObjectThe currently authenticated item.
authedListKeyStringThe list currently authenticated against.
listKeyStringThe key of the list being operated on.
deletedItemObjectThe database record of the deleted item.

afterAuth

OptionTypeDescription
operationString"authenticate"
authedItemObjectThe currently authenticated item.
authedListKeyStringThe list currently authenticated against.
listKeyStringThe key of the list being operated on.
itemObjectThe authenticated item
successBooleanA success indicator returned by authentication strategy
messageStringA success message returned by authentication strategy
tokenStringThe token returned by authentication strategy

afterUnauth

OptionTypeDescription
operationString"unauthenticate"
authedItemObjectThe currently authenticated item.
authedListKeyStringThe list currently authenticated against.
listKeyStringThe key of the list being operated on.
itemIdStringThe ID of the unauthenticated item

On this page

Edit on GitHub