Needlessly Promiscuous, Modularize!

    @rwdt/logger
    TypeScript icon, indicating that this package has built-in type declarations

    1.0.0 • Public • Published

    @rwdt/logger

    Build Status Coverage Status

    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')

    example png

    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')

    set-logger-level.png

    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

    Keywords

    none

    Install

    npm i @rwdt/logger

    DownloadsWeekly Downloads

    4

    Version

    1.0.0

    License

    MIT

    Unpacked Size

    155 kB

    Total Files

    18

    Last publish

    Collaborators

    • lleohao