aghaffar570 / testpkg

a small npm package that stores every log made to the console. great for debugging!

Home Page:https://www.npmjs.com/package/@aghaffar570/testpkg

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

testpkg

install size

A simple npm package that stores every log and prints it to the console. Great for debugging old logs.

install

npm install @aghaffar570/testpkg

usage

const { log, viewLogs, removeLogs } = require('@aghaffar570/testpkg');

log('hello') // '2019-1-29 15:20:08 - hello'
log('goodbye') // '2019-1-29 15:20:08 - goodbye'
log() // '2019-1-29 15:20:08 - NO MSG INPUT'

viewLogs()
// => [ { message: 'hello', time: '2019-1-29 15:25:05' },
//      { message: 'goodbye', time: '2019-1-29 15:25:05' } ]

removeLogs()
// => []

implementation

function logger() {
 const _logs = []
 return {
   log(message) {
     const time = new Date().toLocaleString()
     _logs.push({ message, time })
     console.log(`${time} - ${message}`)
   },
   viewLogs(){
     console.log(_logs)
     return _logs
   },
   removeLogs(){
     console.log(_logs)
     _logs.length = 0
     return _logs
   }
 }
}


module.exports = logger()

About

a small npm package that stores every log made to the console. great for debugging!

https://www.npmjs.com/package/@aghaffar570/testpkg

License:MIT License


Languages

Language:JavaScript 100.0%