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
|
|
@ -95,11 +95,11 @@ Singleton {
|
|||
path: Settings.configDir + "colors.json"
|
||||
watchChanges: true
|
||||
onFileChanged: {
|
||||
console.log("[Colors] Reloading colors from disk")
|
||||
Logger.log("Colors", "Reloading colors from disk")
|
||||
reload()
|
||||
}
|
||||
onAdapterUpdated: {
|
||||
console.log("[Colors] Writing colors to disk")
|
||||
Logger.log("Colors", "Writing colors to disk")
|
||||
writeAdapter()
|
||||
}
|
||||
onLoadFailed: function (error) {
|
||||
|
|
|
|||
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)
|
||||
}
|
||||
}
|
||||
|
|
@ -49,11 +49,11 @@ Singleton {
|
|||
reload()
|
||||
}
|
||||
onLoaded: function () {
|
||||
console.log("[Settings] Loaded")
|
||||
Logger.log("Settings", "Loaded")
|
||||
Qt.callLater(function () {
|
||||
// Only set wallpaper on initial load, not on reloads
|
||||
if (isInitialLoad && adapter.wallpaper.current !== "") {
|
||||
console.log("[Settings] Set current wallpaper", adapter.wallpaper.current)
|
||||
Logger.log("Settings", "Set current wallpaper", adapter.wallpaper.current)
|
||||
WallpapersService.setCurrentWallpaper(adapter.wallpaper.current, true)
|
||||
}
|
||||
isInitialLoad = false
|
||||
|
|
|
|||
|
|
@ -12,7 +12,7 @@ Singleton {
|
|||
property string time: {
|
||||
let timeFormat = Settings.data.location.use12HourClock ? "h:mm AP" : "HH:mm"
|
||||
let timeString = Qt.formatDateTime(date, timeFormat)
|
||||
|
||||
|
||||
if (Settings.data.location.showDateWithClock) {
|
||||
let dayName = date.toLocaleDateString(Qt.locale(), "ddd")
|
||||
dayName = dayName.charAt(0).toUpperCase() + dayName.slice(1)
|
||||
|
|
@ -20,7 +20,7 @@ Singleton {
|
|||
let month = date.toLocaleDateString(Qt.locale(), "MMM")
|
||||
return timeString + " - " + dayName + ", " + day + " " + month
|
||||
}
|
||||
|
||||
|
||||
return timeString
|
||||
}
|
||||
readonly property string dateString: {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue