@exobase/use-logging
v1.0.0-rc.27
Published
Exobase hook to log info about requests
Downloads
150
Readme
title: 'useLogging' description: 'A hook to log request and response information' group: 'Hooks' badge: 'Logging'
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.
Install
yarn add @exobase/use-logging
# or
yarn add @exobase/hooks
Import
import { useLogging } from '@exobase/use-logging'
// or
import { useLogging } from '@exobase/hooks'
Usage
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
)