You're Invited:Meet the Socket Team at BlackHat and DEF CON in Las Vegas, Aug 4-6.RSVP
Socket
Book a DemoInstallSign in
Socket

nn-node-log

Package Overview
Dependencies
Maintainers
1
Versions
9
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install
Package was removed
Sorry, it seems this package was removed from the registry

nn-node-log

Simple Node log with levels, color, and location from file name and line number

0.3.0
unpublished
latest
Source
npmnpm
Version published
Weekly downloads
0
Maintainers
1
Weekly downloads
 
Created
Source

Simple Node log

Simple Node log with levels, color, and log location from file name and line number, inspired from the Golang log package.

NPM version NPM monthly download

  • Caution: This package uses some private APIs from Node, those APIs are not guaranteed to be kept overtime. It's also a new package under heavy developing and has not been well tested yet. If any problem happens, feel free to open an issue.
  • Require:
    • Node >= v8.0.0

Reference

Example

const log = require('nn-node-log')

try {
  process.on('uncaughtException', (err) => {
    log.stack(err)
  })

  // init our express app, router, graphql...

  server.listen(8080, () => log.info('listening on port 8080'))
} catch (err) {
  log.stack(err, 'fatal')
}

Example

API

The exported module is a singleton of lib/Log class. It has the following properties and methods:

log.level

  • string - Default debug
  • A string to specify the current log level of the instance. It should be one of debug, info, warn, error or fatal.

log.debugPrefix

  • string - Default is an empty string
  • A string to specify the debug prefix to filter out the unnecessary debug messages.

log.color

  • A boolean flag to indicate that it should print with color or not. Default is true.

log.skip

  • number - Default 3
  • A number to skip when retrieving the stack trace call layer. We should modify this number when we want to wrap the library inside other function calls.

log.timezone

  • number - Default is the current timezone
  • A number to specify the target timezone to be printed out.

log.setCwd(cwd)

  • Set the current working directory
  • Parameters:
    • cwd:
      • string - Required

log.filterFn

  • Function - Default from the stacktrace package
  • A function to filter the stack layer.

log.filenameFn

  • Function - Default from the stacktrace package
  • A function to get the shortened file name from the stack layer.

log.debug([f, ...args])

log.warn([f, ...args])

log.info([f, ...args])

log.error([f, ...args])

log.fatal([f, ...args])

  • Log with a specified format for each level. With fatal level, it will call process.exit(1) to quit the current process afterwards.
  • Parameters:
    • f:
    • ...args:
      • any - Optional
      • The rest arguments to be formatted with.

log.trace(level[, f, ...args])

  • Print out together with the call layers.
  • Parameters:
    • level:
      • string - Required
      • A string to specify the level to log.
    • f:
    • ...args:
      • any - Optional
      • The rest arguments to be formatted with.

log.stack(err[, level])

  • Pretty print out the error.
  • Parameters:
    • err:
      • Error - Required
      • The error to be printed out.
    • level:
      • string - Optional - Default error
      • A string to specify the level to log.

License

MIT

Keywords

node

FAQs

Package last updated on 30 Dec 2018

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts