@rwdt/logger
v1.0.0
Published
[![Build Status](https://travis-ci.com/remote-web-dev-tools/logger.svg?branch=main)](https://travis-ci.com/remote-web-dev-tools/logger) [![Coverage Status](https://coveralls.io/repos/github/remote-web-dev-tools/logger/badge.svg?branch=main)](https://cover
Downloads
1
Readme
@rwdt/logger
A simple javascript library for log.
Install
Use npm
npm i @rwdt/logger --save
or use yarn
yarn add @rwdt/logger
Usage
Quick start
import { Logger } from '@rwdt/logger'
const logger = new Logger()
logger.debug('debug')
logger.info('info')
logger.warn('warn')
logger.error('error')
Set logger level
import { Logger } from '@rwdt/logger'
const logger = new Logger()
logger.setLevel('WARN') // or const logger = new Logger({level: 'WARN'})
logger.debug('debug')
logger.info('info')
logger.warn('warn')
logger.error('error')
Custom logger appender
write the log to file
import { Logger } from '@rwdt/logger'
import { writeFileSync } from 'fs'
const logger = new Logger()
logger.addAppender(loggingEvent => {
writeFileSync('logger.log', JSON.stringify(), {
flag: 'a'
})
})
// or
// const logger = new Logger({
// appender: [loggingEvent => {
// writeFileSync('logger.log', JSON.stringify(), {
// flag: 'a'
// })
// }]
// })
logger.info('custom appender')
Set context
The context will be set to LoggingEvent
import { Logger } from '@rwdt/logger'
const logger = new Logger({context: 'any type context'})
// or logger.setContext({other: 'context'})
API
See types/index.d.ts