Skip to content

Instantly share code, notes, and snippets.

@vinicius73
Last active November 16, 2018 18:03
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save vinicius73/a896db49d4bdc8270f8a785578df4381 to your computer and use it in GitHub Desktop.
Save vinicius73/a896db49d4bdc8270f8a785578df4381 to your computer and use it in GitHub Desktop.
function formatTime (timeInMs) {
let date = new Date(timeInMs)
// ${date.getDate()}/${date.getMonth()}/${date.getFullYear()}
return `${date.getHours()}:${date.getMinutes()}:${date.getSeconds()}.${date.getMilliseconds()}`
}
function log (type, ...args) {
if (this.$options.debug) {
console[type](`%c[${this.$_id}]${formatTime(Date.now())}>> `,
`background:${type === 'log' ? '#384A5E' : type === 'warn' ? '#F1BF39' : '#FF5370'}; padding: 3px; border-radius: 3px; color: #fff`,
...args,
this.$el
)
}
}
export default {
created () {
this.$_id = `${this.$options.name}-${(Date.now()).toString(32)}`
this.log('debug ON')
},
methods: {
log (...args) {
log.call(this, 'log', ...args)
},
warn (...args) {
log.call(this, 'warn', ...args)
},
error (...args) {
log.call(this, 'error', ...args)
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment