Home

Awesome

roosevelt-logger

Build Status codecov npm

Intuitive, attractive logger for Node.js applications based on Winston. This module was built and is maintained by the Roosevelt web framework team, but it can be used independently of Roosevelt as well.

Install

First declare roosevelt-logger as a dependency in your app.

Usage

Require the package into your application and call its constructor:

const Logger = require('roosevelt-logger')
const logger = new Logger()

logger.log('some info')
//=> some info

logger.warn('a warning')
//=> ⚠️  a warning

logger.error('an error')
//=> ❌  an error

logger.verbose('noisy log only displayed when verbose is enabled')
//=>

logger.log('✅', 'log prepended with a custom emoji or other string')
//=> ✅  log prepended with a custom emoji or other string

Configure logger

Optionally you can pass the logger a set of configs.

Usage with custom configs

Require the package into your application and call its constructor:

const logger = require('roosevelt-logger')({
    methods: {
      verbose: true, // enables verbose logging
      dbError: {     // create custom error called dbError
          type: 'error',
          prefix: '🗄'
      }
    },
    params: {
      disable: ['LOADED_MOCHA_OPTS'] // disable logging during Mocha tests
    }
})

logger.log('some info')
//=> some info

logger.warn('a warning')
//=> ⚠️  a warning

logger.error('an error')
//=> ❌  an error

logger.verbose('noisy log only displayed when verbose is enabled')
//=> noisy log only displayed when verbose is enabled

logger.dbError('custom log for database errors')
//=> 🗄  custom log for database errors

Instance properties exposed by roosevelt-logger

.winston()

The Winston module that roosevelt-logger uses internally.

.winstonInstance

The specific Winston object instance instantiated by roosevelt-logger.

.transports

The default Winston transports enabled by roosevelt-logger.

.enableLogging()

Programmatically enable the logger.

.disableLogging()

Programmatically disable the logger.

.enablePrefix()

Programmatically enable all log prefixes.

.disablePrefix()

Programmatically disable all log prefixes.

.createLogMethod(config)

Programmatically create a new logger method.

  logger.createLogMethod({
    name: 'dbError',
    type: 'error'
    prefix: '💥',
    color: 'red'
  })

  logger.dbError('Our whole stack is in crisis mode!')
  //=> 💥 Our whole stack is in crisis mode!