@rcp/util.createlogger

Create namespace isomorphic logger

Usage no npm install needed!

<script type="module">
  import rcpUtilCreatelogger from 'https://cdn.skypack.dev/@rcp/util.createlogger';
</script>

README

@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