Update js logging.

This commit is contained in:
sn0w12
2024-08-24 20:30:02 +02:00
parent a51ddb6c57
commit 4fe93f0c44
4 changed files with 43 additions and 17 deletions
+2 -1
View File
@@ -518,7 +518,8 @@ async def add_lora_loaders(request):
with open(json_path, "w") as file:
json.dump(data, file, indent=4)
return web.json_response({"message": f"Lora loaders: {new_unique_loaders} added successfully."})
new_unique_loaders_str = "[" + ", ".join(str(loader) for loader in new_unique_loaders) + "]"
return web.json_response({"message": f"Loaders added: {new_unique_loaders_str}"})
except json.JSONDecodeError:
return web.json_response({"error": "Invalid JSON format."}, status=400)
+1 -2
View File
@@ -1,5 +1,4 @@
import { SettingUtils } from './sn0w.js';
import { app } from '../../../scripts/app.js';
import { api } from '../../../scripts/api.js';
async function updateLoggingLevel() {
@@ -22,7 +21,7 @@ async function updateLoggingLevel() {
await api.fetchApi(`${SettingUtils.API_PREFIX}/update_logging_level`, {
method: 'GET',
});
SettingUtils.logSn0w(`Logging levels selected:\n${await SettingUtils.getSetting("sn0w.LoggingLevel")}`, "debug")
SettingUtils.logSn0w("Logging Levels Updated", "debug", "setting", `Logging levels selected:\n${loggingArray}`)
}
const debouncedUpdateLoggingLevel = SettingUtils.debounce(updateLoggingLevel, 1000);
+1 -1
View File
@@ -13,7 +13,7 @@ async function addLoraLoaders(loraLoaders) {
})
const data = await response.json();
SettingUtils.logSn0w(data.message, "informational");
SettingUtils.logSn0w("Lora Loaders successfully added.", "informational", "lora", data.message);
} catch (error) {
SettingUtils.logSn0w(error.message, "error");
}
+39 -13
View File
@@ -10,8 +10,8 @@ export class SettingUtils {
const currentTime = Date.now();
const cacheEntry = this.settingsCache[url];
// Check if the cache entry exists and is still valid (not older than 10 seconds)
if (cacheEntry && currentTime - cacheEntry.timestamp < 10000) {
// Check if the cache entry exists and is still valid (not older than 1 seconds)
if (cacheEntry && currentTime - cacheEntry.timestamp < 1000) {
return cacheEntry.data;
}
@@ -32,6 +32,7 @@ export class SettingUtils {
timestamp: currentTime
};
SettingUtils.logSn0w(`Got setting: ${url}`, "debug", "setting", data);
return data;
} catch (error) {
console.error('There was a problem with the fetch operation:', error);
@@ -463,7 +464,8 @@ export class SettingUtils {
entry.style.alignItems = 'center';
}
};
let arr = []
let starred = [0, []];
menuEntries.forEach((entry) => {
const value = entry.getAttribute('data-value');
let filename = value;
@@ -486,12 +488,15 @@ export class SettingUtils {
// Check if star is already added to avoid duplication
if (!entry.querySelector('span')) {
entry.appendChild(star);
starred[0]++;
starred[1].push(filename);
}
// Initial background color check
const currentBgColor = window.getComputedStyle(entry).backgroundColor;
checkAndUpdateBackgroundColor(entry, currentBgColor);
}
SettingUtils.logSn0w(`Total Favourited Items: ${starred[0]}`, "debug", "node", starred[1])
});
}
@@ -554,21 +559,42 @@ export class SettingUtils {
};
}
static async logSn0w(message, type) {
static async logSn0w(message, type, category = "", detailMessage = "") {
const loggingLevels = await SettingUtils.getSetting("sn0w.LoggingLevel");
const logColors = {
"error": "red",
"warning": "yellow",
};
const alwaysLog = ["emergency", "alert", "critical", "error"]
const logLevel = type.toLowerCase();
const color = logColors[logLevel] || "rgb(136, 23, 152)";
if (alwaysLog.includes(logLevel) || loggingLevels.includes(type.toUpperCase())) {
console.log(`%c[sn0w]`, `color: ${color};`, message);
if (!alwaysLog.includes(logLevel) && !loggingLevels.includes(type.toUpperCase())) {
console.log("dont log")
return;
}
const prefix = "sn0w";
const generalCss = 'color: white; padding: 2px 6px 2px 4px; font-weight: lighter;'
let customCSS = generalCss + ' border-radius: 3px;';
const logColors = {
"error": "#c50f1f",
"warning": "#c19c00",
};
const categoryColors = {
"api": "#c19c00",
"lora": "#3a96dd",
}
const color = logColors[logLevel] || "#881798";
const categoryCSS = category ? `background-color: ${categoryColors[category.toLowerCase()] || "#13a10e"}; border-radius: 0 3px 3px 0; margin-left: -5px;` : '';
const logMessage = category
? [`%c${prefix}%c${category}`, `${customCSS.replace("6px", "10px")} background-color: ${color};`, `${generalCss} ${categoryCSS}`, message] // Category
: [`%c${prefix}`, `${customCSS} background-color: ${color};`, message]; // No Category
console.groupCollapsed(...logMessage);
if (detailMessage != "") {
console.log(detailMessage);
}
console.trace();
console.groupEnd();
}
static drawSigmas(sigmas) {