Last active
November 16, 2018 18:03
-
-
Save vinicius73/a896db49d4bdc8270f8a785578df4381 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
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