1.1.3 • Published 3 years ago

xlogger-pretty v1.1.3

Weekly downloads
-
License
MIT
Repository
github
Last release
3 years ago

xlogger-pretty

A logger as pretty and easy to use as the Python logging library.

Install

npm install xlogger-pretty
yarn add xlogger-pretty

Quick Start

import Logger from 'xlogger-pretty'

const logger = new Logger()

logger.log('This is a normal log.')
logger.info('This is an info log.')
logger.debug('This is a debug log.')
logger.notice('This is a notice log.')
logger.warn('This is a warn log.')
logger.error('This is an error log.')
logger.success('This is a success log.')

image-20210803160255373

Options

nametypedefaultdesc
levelnumber/string0日志输出级别,可以数字或者字符串,详情见下面Level说明
formatstringlabel自定义日志输出格式
datetimeFormatstringYYYY-MM-DD HH:mm:ss日志时间格式
msgColorbooleanfalse日志内容是否为彩色
wrapLabelbooleanfalse日志标签是否被[]包裹
uppercaseLabelbooleanfalse日志标签是否大写
colorsobjectnull自定义日志标签输出颜色, { success: green },颜色值取kolorist库中的颜色函数 (import { green } from 'kolorist')

Custom Colors

import * as colors from 'kolorist'

const logger = new Logger({
  uppercaseLabel: true,
  colors: {
    info: colors.bgBlue,
    debug: colors.bgMagenta,
    notice: colors.bgCyan,
    warn: colors.bgYellow,
    error: colors.bgRed,
    success: colors.bgGreen
  }
})

logger.info('This is an info log.')
logger.debug('This is a debug log.')
logger.notice('This is a notice log.')
logger.warn('This is a warn log.')
logger.error('This is an error log.')
logger.success('This is a success log.')

image-20210803203120367

Custom Display Format

Level log方法不受级别控制

LevelStringLevelNumber
success0
debug1
info2
notice3
warn4
error5

Exposed variable

namedefaultdesc
labelinfo/debug/notice/warn/error/success日志标签
msgmsg日志内容
datetime2021-07-05 17:21:01当前时间

Example

xxx format占位标记, 实际运行会转换为真实的值。

const logger = new Logger({
  format: '[datetime] - [label] - [msg]',
  wrapLabel: true,
  uppercaseLabel: true,
  msgColor: true
})

logger.log('This is a normal log.')
logger.info('This is an info log.')
logger.debug('This is a debug log.')
logger.notice('This is a notice log.')
logger.warn('This is a warn log.')
logger.error('This is an error log.')
logger.success('This is a success log.')

image-20210803163726963

1.1.3

3 years ago

1.1.2

3 years ago

1.1.1

3 years ago

1.1.0

3 years ago

1.0.5

3 years ago

1.0.4

3 years ago

1.0.3

3 years ago

1.0.2

3 years ago

1.0.1

3 years ago

1.0.0

3 years ago