mirror of
https://github.com/AvengeMedia/DankMaterialShell.git
synced 2026-04-30 17:42:06 -04:00
logger: add a dedicated QML logging Singleton
- adds log.info/error/debug/warn/fatal - adds ability to write logs to any file - add CLI options in addition to env to set log levels
This commit is contained in:
@@ -5,9 +5,11 @@ import QtQuick
|
||||
import Quickshell
|
||||
import Quickshell.Io
|
||||
import qs.Common
|
||||
import qs.Services
|
||||
|
||||
Singleton {
|
||||
id: root
|
||||
readonly property var log: Log.scoped("DMSService")
|
||||
|
||||
property bool dmsAvailable: false
|
||||
property var capabilities: []
|
||||
@@ -198,14 +200,14 @@ Singleton {
|
||||
try {
|
||||
response = JSON.parse(line);
|
||||
} catch (e) {
|
||||
console.warn("DMSService: Failed to parse request response:", line.substring(0, 100));
|
||||
log.warn("Failed to parse request response:", line.substring(0, 100));
|
||||
return;
|
||||
}
|
||||
const isClipboard = clipboardRequestIds[response.id];
|
||||
if (isClipboard)
|
||||
delete clipboardRequestIds[response.id];
|
||||
else
|
||||
console.log("DMSService: Request socket <<", line);
|
||||
log.debug("Request socket <<", line);
|
||||
handleResponse(response);
|
||||
}
|
||||
}
|
||||
@@ -232,11 +234,11 @@ Singleton {
|
||||
try {
|
||||
response = JSON.parse(line);
|
||||
} catch (e) {
|
||||
console.warn("DMSService: Failed to parse subscription event:", line.substring(0, 100));
|
||||
log.warn("Failed to parse subscription event:", line.substring(0, 100));
|
||||
return;
|
||||
}
|
||||
if (!line.includes("clipboard"))
|
||||
console.log("DMSService: Subscribe socket <<", line);
|
||||
log.debug("Subscribe socket <<", line);
|
||||
handleSubscriptionEvent(response);
|
||||
}
|
||||
}
|
||||
@@ -251,9 +253,9 @@ Singleton {
|
||||
request.params = {
|
||||
"services": activeSubscriptions
|
||||
};
|
||||
console.log("DMSService: Subscribing to services:", JSON.stringify(activeSubscriptions));
|
||||
log.debug("Subscribing to services:", JSON.stringify(activeSubscriptions));
|
||||
} else {
|
||||
console.log("DMSService: Subscribing to all services");
|
||||
log.debug("Subscribing to all services");
|
||||
}
|
||||
|
||||
subscribeSocket.send(request);
|
||||
@@ -291,7 +293,7 @@ Singleton {
|
||||
} else {
|
||||
const filtered = activeSubscriptions.filter(s => s !== service);
|
||||
if (filtered.length === 0) {
|
||||
console.warn("DMSService: Cannot remove last subscription");
|
||||
log.warn("Cannot remove last subscription");
|
||||
return;
|
||||
}
|
||||
subscribe(filtered);
|
||||
@@ -316,7 +318,7 @@ Singleton {
|
||||
if (response.error) {
|
||||
if (response.error.includes("unknown method") && response.error.includes("subscribe")) {
|
||||
if (!shownOutdatedError) {
|
||||
console.error("DMSService: Server does not support subscribe method");
|
||||
log.error("Server does not support subscribe method");
|
||||
ToastService.showError(I18n.tr("DMS out of date"), I18n.tr("To update, run the following command:"), updateCommand);
|
||||
shownOutdatedError = true;
|
||||
}
|
||||
@@ -336,7 +338,7 @@ Singleton {
|
||||
cliVersion = data.cliVersion || "";
|
||||
capabilities = data.capabilities || [];
|
||||
|
||||
console.info("DMSService: Connected (API v" + apiVersion + ", CLI " + cliVersion + ") -", JSON.stringify(capabilities));
|
||||
log.info("Connected (API v" + apiVersion + ", CLI " + cliVersion + ") -", JSON.stringify(capabilities));
|
||||
|
||||
if (apiVersion < expectedApiVersion) {
|
||||
ToastService.showError("DMS server is outdated (API v" + apiVersion + ", expected v" + expectedApiVersion + ")");
|
||||
@@ -401,7 +403,7 @@ Singleton {
|
||||
|
||||
function sendRequest(method, params, callback) {
|
||||
if (!isConnected) {
|
||||
console.warn("DMSService.sendRequest: Not connected, method:", method);
|
||||
log.warn("DMSService.sendRequest: Not connected, method:", method);
|
||||
if (callback) {
|
||||
callback({
|
||||
"error": "not connected to DMS socket"
|
||||
@@ -427,7 +429,7 @@ Singleton {
|
||||
if (method.startsWith("clipboard")) {
|
||||
clipboardRequestIds[id] = true;
|
||||
} else {
|
||||
console.log("DMSService.sendRequest: Sending request id=" + id + " method=" + method);
|
||||
log.debug("DMSService.sendRequest: Sending request id=" + id + " method=" + method);
|
||||
}
|
||||
requestSocket.send(request);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user