refactor(logging): AzLogs v1.4.1 with dynamic storage and utilities
Enhance logging system with configurable module names and dynamic localStorage keys to avoid conflicts between multiple plugin instances. - Add LOG_MODULE_NAME and DEFAULT_LOGGER_NAME to web/log_system/config.js - Update logger.js to use dynamic storage keys based on module name - Change window property from ResolutionMasterLogger to dynamic key - Add PyDoc metadata to core/log_system/config.py - Add JSDoc metadata blocks to all web log_system files Reorganize web utilities: - Move css-loader.js from web/ to web/utils/ - Add ErrorHandler.js for centralized error handling - Add ResourceManager.js for stylesheet and template loading rename: web/css-loader.js => web/utils/css-loader.js
This commit is contained in:
@@ -0,0 +1,51 @@
|
||||
// @ts-ignore
|
||||
import { $el } from "../../../scripts/ui.js";
|
||||
import { createModuleLogger } from "../log_system/LoggerUtils.js";
|
||||
import { withErrorHandling, createValidationError, createNetworkError } from "./ErrorHandler.js";
|
||||
const log = createModuleLogger('ResourceManager');
|
||||
export const addStylesheet = withErrorHandling(function (url) {
|
||||
if (!url) {
|
||||
throw createValidationError("URL is required", { url });
|
||||
}
|
||||
log.debug('Adding stylesheet:', { url });
|
||||
if (url.endsWith(".js")) {
|
||||
url = url.substr(0, url.length - 2) + "css";
|
||||
}
|
||||
$el("link", {
|
||||
parent: document.head,
|
||||
rel: "stylesheet",
|
||||
type: "text/css",
|
||||
href: url.startsWith("http") ? url : getUrl(url),
|
||||
});
|
||||
log.debug('Stylesheet added successfully:', { finalUrl: url });
|
||||
}, 'addStylesheet');
|
||||
export function getUrl(path, baseUrl) {
|
||||
if (!path) {
|
||||
throw createValidationError("Path is required", { path });
|
||||
}
|
||||
if (baseUrl) {
|
||||
return new URL(path, baseUrl).toString();
|
||||
}
|
||||
else {
|
||||
// @ts-ignore
|
||||
return new URL("../" + path, import.meta.url).toString();
|
||||
}
|
||||
}
|
||||
export const loadTemplate = withErrorHandling(async function (path, baseUrl) {
|
||||
if (!path) {
|
||||
throw createValidationError("Path is required", { path });
|
||||
}
|
||||
const url = getUrl(path, baseUrl);
|
||||
log.debug('Loading template:', { path, url });
|
||||
const response = await fetch(url);
|
||||
if (!response.ok) {
|
||||
throw createNetworkError(`Failed to load template: ${url}`, {
|
||||
url,
|
||||
status: response.status,
|
||||
statusText: response.statusText
|
||||
});
|
||||
}
|
||||
const content = await response.text();
|
||||
log.debug('Template loaded successfully:', { path, contentLength: content.length });
|
||||
return content;
|
||||
}, 'loadTemplate');
|
||||
Reference in New Issue
Block a user