-
-
Save rogeriomq/67688fcfbe9ef75d3345c717cfa7d4eb 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
export default (enable = false) => { | |
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 (enable) { | |
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 | |
) | |
} | |
} | |
return { | |
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