Hooks
A hook to log request and response information
Provides an Exobase hook that will log information about the request given a string of tokens.
This module inspired by morgan, the logging middleware library for Express.
yarn add @exobase/use-logging
# or
yarn add @exobase/hooks
import { useLogging } from '@exobase/use-logging'
// or
import { useLogging } from '@exobase/hooks'
import { compose } from 'radash'
import type { Props } from '@exobase/core'
import { useNext } from '@exobase/use-next'
import { useLogging } from '@exobase/use-logging'
export const listLibraries = async (props: Props) => {
return db.libraries.list()
}
export default compose(
useNext(),
useLogging(),
useLogging('[:method] :path at :date(iso) -> :status in :elapsed(ms'),
useLogging('[:method] :request-id', {
format: message => JSON.stringify({ message }),
logger: console,
tokens: (l, p, e, r) => ({
'request-id': () => p.request.headers['x-request-id']
})
}),
listLibraries
)