log-audit v0.3.0
Log Audit
Log audit is a simple tool to write in a standardized way to stdout.
Install
npm i --save log-auditUsage
I recommend instantiating the logger in a central file and then exporting that file for useage throughout your app. For example:
logger.js
import logAudit from 'log-audit'
const {info, debug, audit} = logAudit(options, defaultFields)
export {info, debug, audit}some-other-file.js
import {info} from 'logger'
info(fields)fields should be an object of key value pairs that will be merged with the existing data. Ad-hoc type of data belongs here, ie: userId, etc
defaultFields should be an object of key value pairs that will appear on every call to logger automatically. Data that belongs on every request should be placed here, ie: timestamp, etc
Example:
info({
userId: 'slk39lskj',
endpoint: '/courses',
method: 'GET',
foo: 'bar'
})API
logAudit([options,defaultFields])
Instantiates the logger with optional options and default fields
options:
- console: boolean - Defaults to true. If true,
console.logwill run for every log call - consoleFormat: string -
json|keyvalue- Determines ifconsole.loglogs in key/value format or json format. - hideLogs: boolean - When true, hides all log messages. Not recommended for production.
- kafka: boolean - When true, log-audit will also post to kafka.
- kafkaTopic: string - Topic to be used for kafka. Required when
kafkais set totrue. - token: string - API token to be used for posting to kafka. Required when
kafkais set totrue. - baseUrl: string - Url to be used to post to kafka, ie
https://domain.com. Required whenkafkais set totrue. - seconds: boolean - Defaults to false. When true, divides by 1000 to give you seconds instead of milliseconds.
defaultFields:
An object of any values. This object will be used applied any time a log fn is called.
The logAudit function returns an object of functions which can then be used to log their appropriate level of logs:
- INFO: Informational logs, eg: Server has started on port 3004
- AUDIT: Information that would be useful for auditing, eg: A user created an item, a resource was deleted, etc...
- DEBUG: Debug info that would only be turned on when a config is set to allow for it.
- SENSITIVE: Stuff that shouldn't be logged at all, like SSNs and such. These logs will not show up... anywhere.