Last active
August 26, 2022 13:10
-
-
Save tawfiknasser/d26cd41f1c72bad55f7a3bc97ab94ce9 to your computer and use it in GitHub Desktop.
simple custom log with stack tracer
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module.exports = (...args) => { | |
const stack = Error().stack | |
let lines = stack.split('\n').slice(2, 3).join('').trim() | |
const d = new Date(); | |
console.log(formatDate(d), '::App::', ...args, '::', lines) | |
} | |
const formatDate = (d)=>`[${d.getFullYear()}-${d.getMonth()}-${d.getDate()} ${d.getHours()}:${d.getMinutes()}:${d.getSeconds()}:${d.getMilliseconds()}]` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const log = require('./log.js') | |
log("hii") | |
// prints: [2020-1-15 16:6:58:169] ::App:: hii :: at <where> (<file_path>.js:<line>:<column>) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment