Skip to content

Instantly share code, notes, and snippets.

@KarmaBlackshaw
Last active July 24, 2022 15:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save KarmaBlackshaw/33d7b4bf5ef22a2a265e5e84f14856a1 to your computer and use it in GitHub Desktop.
Save KarmaBlackshaw/33d7b4bf5ef22a2a265e5e84f14856a1 to your computer and use it in GitHub Desktop.
const chalk = require('chalk')
const { log } = console
const cwd = process.cwd()
function proxiedLog (...args) {
const line = (((new Error('log'))
.stack.split('\n')[2] || '…')
.match(/\(([^)]+)\)/) || ['not found'])[1]
const stack = line
.replace(cwd, '')
.replace(/^\\|^\/|\/$|\\$/g, '')
log.call(console, `${chalk.underline.green(stack)}:`, ...args)
}
console.info = proxiedLog
console.log = proxiedLog
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment