@nodedk/logger
logger#
Append formatted values to a log file asynchronously.
Install#
npm i @nodedk/logger
Usage#
var logger = require('@nodedk/logger')
var log = logger('application.log')
log('Application started')
log('Processed %d records for %s', 12, 'Ada')
log({ event: 'ready', workers: 2 })
log(new Date())
API#
logger(file)#
file is a file path, resolved from the working directory. Returns log(...args). The parent directory must exist.
log(...args)#
Appends a newline after each entry. Multiple arguments use util.format; a single object uses indented JSON, and a single Date uses ISO format. Returns undefined immediately.
If the file append fails, the same entry is written to standard output.
To route console output to a file:
var logger = require('@nodedk/logger')
var log = logger('application.log')
console.log = log
console.error = log
Created by Vidar Eldøy