Using a custom logger with colors and timestamp instead of console.xxx
This commit is contained in:
parent
4794477be3
commit
e800bc161d
34 changed files with 278 additions and 236 deletions
33
Commons/Logger.qml
Normal file
33
Commons/Logger.qml
Normal file
|
|
@ -0,0 +1,33 @@
|
|||
pragma Singleton
|
||||
|
||||
import Quickshell
|
||||
import qs.Commons
|
||||
|
||||
Singleton {
|
||||
id: root
|
||||
|
||||
function _formatMessage(...args) {
|
||||
var t = Time.getFormattedTimestamp()
|
||||
if (args.length > 1) {
|
||||
var module = args.shift()
|
||||
return `\x1b[36m${t}\x1b[0m \x1b[35m[${module}]\x1b[0m ` + args.join(" ")
|
||||
} else {
|
||||
return `\x1b[36m${t}\x1b[0m ` + args.join(" ")
|
||||
}
|
||||
}
|
||||
|
||||
function log(...args) {
|
||||
var msg = _formatMessage(...args)
|
||||
console.log(msg)
|
||||
}
|
||||
|
||||
function warn(...args) {
|
||||
var msg = _formatMessage(...args)
|
||||
console.warn(msg)
|
||||
}
|
||||
|
||||
function error(...args) {
|
||||
var msg = _formatMessage(...args)
|
||||
console.error(msg)
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue