Have ideas to improve npm?Join in the discussion! »

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

    1.0.0 • Public • Published

    Builder Box Logger

    This package handles everything related to the logging of the Framework Builder Box

    MIT License Build Status Coverage Status codecov code style: prettier dependencies Status devDependencies Status peerDependencies Status

    Install

    yarn add @builderbox/logger

    or

    npm install --save @builderbox/logger

    Quick start

    You have to init a Logger object and you can use all winston transporter

    const { transports } = require('winston')
    const { Logger } = new require('./lib/logger')
    const logger = new Logger([ new transports.Console() ])
     
    logger.debug("test one...")
    logger.info("testing two...")
    logger.warn("testing three...")
    logger.error("testing four...")

    then this is the result

    [2020-09-15 10:24:22] DEBUG test one... {}
    [2020-09-15 10:24:22] INFO testing two... {}
    [2020-09-15 10:24:22] WARN testing three... {}
    [2020-09-15 10:24:22] ERROR testing four... {}

    You can add all the context that you need

    logger.error("testing five...", {any: 'any value', obj : {}, arr: [1,2,3]})

    And then..

    [2020-09-15 10:30:00] ERROR testing five... {"any":"any value","obj":{},"arr":[1,2,3]}

    Log exceptions as principal content

    logger.error("testing five...", {any: 'any value', obj : {}, arr: [1,2,3]})

    Then...

    [2020-09-15 10:38:25] ERROR Error: Something is wrong in test six {"any":"any value","obj":{},"arr":[1,2,3],"exception":{"message":"Error: Something is wrong in test six","trace":["Object.<anonymous> (/absolute/path/file.js:11:14)","Module._compile (internal/modules/cjs/loader.js:1137:30)","Object.Module._extensions..js (internal/modules/cjs/loader.js:1157:10)","Module.load (internal/modules/cjs/loader.js:985:32)","Function.Module._load (internal/modules/cjs/loader.js:878:14)","Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:71:12)","internal/main/run_main_module.js:17:47"]}}

    Or you can log exception as e context

    logger.error("testing seven...", new Error('Something is wrong'))
    [2020-09-15 10:33:44] ERROR testing seven... {"exception":{"message":"Error: Something is wrong","trace":["Object.<anonymous> (/absolute/path/file.js:12:34)","Module._compile (internal/modules/cjs/loader.js:1137:30)","Object.Module._extensions..js (internal/modules/cjs/loader.js:1157:10)","Module.load (internal/modules/cjs/loader.js:985:32)","Function.Module._load (internal/modules/cjs/loader.js:878:14)","Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:71:12)","internal/main/run_main_module.js:17:47"]}}

    Install

    npm i @builderbox/logger

    DownloadsWeekly Downloads

    0

    Version

    1.0.0

    License

    MIT

    Unpacked Size

    138 kB

    Total Files

    48

    Last publish

    Collaborators

    • avatar