Naming Prosecution Mitigator
Miss any of our Open RFC calls?Watch the recordings here! »

runty-logger

2.1.0 • Public • Published

runty-logger

package version package downloads standard-readme compliant package license make a pull request Greenkeeper badge

Pure, lightweight, multi-level, flexible logger

Table of Contents

Install

This project uses node and npm.

$ npm install runty-logger
# OR 
$ yarn add runty-logger

Usage

const createLogger = require('runty-logger')
 
// All arguments are optional. Shown with defaults
const log = createLogger({
  level: 'info',
  name: '',
  levels: {
    trace: 10,
    debug: 20,
    info: 30,
    warn: 40,
    error: 50,
    fatal: 60
  },
  // Control how the message is logged
  log: function defaultLog (timestamp, level = '', name) {
    const outputName = name && name.length ? `${name} -` : '-'
    return (message, data = '') => {
      const output = `${timestamp} ${level.toUpperCase().padEnd(5)} ${outputName}`
      console.log(output, message, data)
      return data || message
    }
  }
})
 
log.trace('a') // will not do anything
log.debug('b') // will not do anything
log.info('c') // 12:37:33 INFO  - c
log.warn('d') // 12:37:33 WARN  - d
log.error('e') // 12:37:33 ERROR - e
log.fatal('f') // 12:37:33 FATAL - f
 
const someBool = true
const someObject = {foo: 5}
 
// Returns value provided for cleaning logging
if (log.info('Some bool set:', someBool)) { // 12:37:33 INFO  - Some bool set: true
  log.info('Ran!') // 12:37:33 INFO  - Ran!
}
 
if (log.info('someObject.foo', someObject.foo) > 1) { // 12:37:33 INFO  - someObject.foo 5
  log.info('Ran!') // 12:37:33 INFO  - Ran!
}
 

Contribute

  1. Fork it and create your feature branch: git checkout -b my-new-feature
  2. Commit your changes: git commit -am 'Add some feature'
  3. Push to the branch: git push origin my-new-feature
  4. Submit a pull request

License

MIT

Install

npm i runty-logger

DownloadsWeekly Downloads

9

Version

2.1.0

License

MIT

Unpacked Size

211 kB

Total Files

16

Last publish

Collaborators

  • avatar