@rcp/util.createlogger
TypeScript icon, indicating that this package has built-in type declarations

2.0.0 • Public • Published

@rcp/util.createlogger

NPM version NPM Downloads

The internal about common isomorphic logger with namespace.

Installation

npm install @rcp/util.createlogger
# or use yarn
yarn add @rcp/util.createlogger

Usage

import createLogger from '@rcp/util.createlogger'
const logger = createLogger('@rcp/hoc.i18n')

logger.info('%s abc', 'ok') // alias `log`
logger.success({ a: '222' }, 'ok')
logger.warn({})
logger.debug()
logger.error()
logger.invariant(typeof document !== 'undefined', 'the library should be used in browser environment.')

API

createLogger(namespace?: string, opts)

Parameters

namespace

The namespace of logger.

opts
  • prefix: (default: '(')

  • suffix: (default: ')')

  • typeMap: eg

    {
      Log: "I'm a Log",
      Success: "Wow!",
      Warning: "Warn!",
      Error: "Error happened",
    }
    

The formatted string are composed by {type}{prefix}{namespace}{suffix}: {message}.

e.g. Success(foo): Done!

Returns

info: (alias: log)
  • Type: function
success
  • Type: function
warn
  • Type: function
debug
  • Type: function
error
  • Type: function
invariant

It will throw Error with message when check is false

  • Type: (check: boolean, message?: string) => void

Related

Authors

This library is written and maintained by imcuttle, mailto:moyuyc95@gmail.com.

License

MIT

Package Sidebar

Install

npm i @rcp/util.createlogger

Weekly Downloads

1

Version

2.0.0

License

MIT

Unpacked Size

24.6 kB

Total Files

25

Last publish

Collaborators

  • moyuyc