Skip to content

Instantly share code, notes, and snippets.

@tawfiknasser
Last active August 26, 2022 13:10
Show Gist options
  • Save tawfiknasser/d26cd41f1c72bad55f7a3bc97ab94ce9 to your computer and use it in GitHub Desktop.
Save tawfiknasser/d26cd41f1c72bad55f7a3bc97ab94ce9 to your computer and use it in GitHub Desktop.
simple custom log with stack tracer
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()}]`
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