diff --git a/ivette/src/dome/misc/system.ts b/ivette/src/dome/misc/system.ts index 58c8badba810a5a07a0cabb44b89caa0b66600a8..2d1067fda2c6e32688e5e077628d22dd2ff5cfed 100644 --- a/ivette/src/dome/misc/system.ts +++ b/ivette/src/dome/misc/system.ts @@ -26,7 +26,6 @@ */ /* eslint-disable max-len */ -/* eslint-disable no-console */ // -------------------------------------------------------------------------- // --- Evolved Spawn Process @@ -38,6 +37,38 @@ import Exec from 'child_process'; import fspath from 'path'; import fs from 'fs'; +// -------------------------------------------------------------------------- +// --- Logging +// -------------------------------------------------------------------------- + +/** Development mode flag */ +export const DEVEL = process.env.NODE_ENV !== 'production'; + +export class Debug { + moduleName: string; + constructor(moduleName: string) { + this.moduleName = moduleName; + } + + /* eslint-disable no-console */ + + log(...args: unknown[]): void { + if (DEVEL) console.log(`[${this.moduleName}]`, ...args); + } + + warn(...args: unknown[]): void { + if (DEVEL) console.warn(`[${this.moduleName}]`, ...args); + } + + error(...args: unknown[]): void { + if (DEVEL) console.error(`[${this.moduleName}]`, ...args); + } + + /* eslint-enable no-console */ +} + +const D = new Debug('dome'); + // -------------------------------------------------------------------------- // --- Platform Specificities // -------------------------------------------------------------------------- @@ -55,7 +86,7 @@ switch (process.platform) { case 'sunos': thePlatform = 'linux'; break; default: - console.warn(`Unkwnon '${process.platform}' (fallback to 'linux')`); + D.warn(`Unknown '${process.platform}' (fallback to 'linux')`); thePlatform = 'linux'; break; } @@ -72,13 +103,6 @@ switch (process.platform) { */ export const platform = thePlatform; -// -------------------------------------------------------------------------- -// --- Logging -// -------------------------------------------------------------------------- - -/** Development mode flag */ -export const DEVEL = process.env.NODE_ENV !== 'production'; - // -------------------------------------------------------------------------- // --- System Emitter // -------------------------------------------------------------------------- @@ -107,7 +131,7 @@ export function atExit(callback: Callback): void { export function doExit(): void { exitJobs.forEach((fn) => { try { fn(); } - catch (err) { console.error('[Dome] atExit:', err); } + catch (err) { D.error('atExit:', err); } }); exitJobs.length = 0; } @@ -399,7 +423,7 @@ async function rmDirRec(path: string): Promise<void> { return; } } catch (err) { - if (DEVEL) console.warn('[Dome.rmDirRec]', err); + D.warn(err); } } @@ -444,7 +468,7 @@ atExit(() => { childprocess.forEach((process, pid) => { try { process.kill(); } catch (err) { - if (DEVEL) console.warn('[Dome.atExit] killing process', pid, err); + D.warn('killing process', pid, err); } }); }); @@ -481,7 +505,7 @@ function pipeTee(std: Readable, fd: number): void { if (!fd) return; const out = fs.createWriteStream('<ignored>', { fd, encoding: 'utf-8' }); out.on('error', (err) => { - console.warn('[Dome] can not pipe:', err); + D.warn('can not pipe:', err); std.unpipe(out); }); std.pipe(out); diff --git a/ivette/src/dome/renderer/data/json.ts b/ivette/src/dome/renderer/data/json.ts index 8cd23bd18f20c7c80df3f97b4c1c9d5d2fc8cc31..1d0f78cc81d048dc227598730cf2cd6344d08ad8 100644 --- a/ivette/src/dome/renderer/data/json.ts +++ b/ivette/src/dome/renderer/data/json.ts @@ -32,7 +32,9 @@ @module dome/data/json */ -import { DEVEL } from 'dome/system'; +import { Debug } from 'dome/system'; + +const D = new Debug('Dome.json'); export type json = undefined | null | boolean | number | string | @@ -52,7 +54,7 @@ export function parse(text: string, noError = false): json { try { return JSON.parse(text); } catch (err) { - if (DEVEL) console.error('[Dome.json] Invalid format:', err); + D.error('Invalid format:', err); return undefined; } } else @@ -225,7 +227,7 @@ export function jCatch<A>(fn: Loose<A>, fallBack: A): Safe<A> { try { return fn(js) ?? fallBack; } catch (err) { - if (DEVEL) console.warn('[Dome.json]', err); + D.warn(err); return fallBack; } }; @@ -240,7 +242,7 @@ export function jTry<A>(fn: Loose<A>, defaultValue?: A): Loose<A> { try { return fn(js) ?? defaultValue; } catch (err) { - if (DEVEL) console.warn('[Dome.json]', err); + D.warn(err); return defaultValue; } }; diff --git a/ivette/src/dome/renderer/dome.tsx b/ivette/src/dome/renderer/dome.tsx index 70f102fbe7757883419890b3e0b4d5dca1829c05..98369b95976e2519c99135ce248e48d427c2082f 100644 --- a/ivette/src/dome/renderer/dome.tsx +++ b/ivette/src/dome/renderer/dome.tsx @@ -75,8 +75,8 @@ function setContextAppNode(): HTMLElement | null { // --- Helpers // -------------------------------------------------------------------------- -/** Configured to be `'true'` when in development mode. */ -export const { DEVEL } = System; +/** DEVEL is configured to be `'true'` when in development mode. */ +export const { DEVEL, Debug } = System; export type PlatformKind = 'linux' | 'macos' | 'windows'; @@ -815,30 +815,3 @@ export function useGlobalSettings<A extends Json.json>( } // -------------------------------------------------------------------------- -// --- Pretty Printing (Browser Console) -// -------------------------------------------------------------------------- - -export class Debug { - moduleName: string; - constructor(moduleName: string) { - this.moduleName = moduleName; - } - - /* eslint-disable no-console */ - - log(...args: any): void { - if (DEVEL) console.log(`[${this.moduleName}]`, ...args); - } - - warn(...args: any): void { - if (DEVEL) console.warn(`[${this.moduleName}]`, ...args); - } - - error(...args: any): void { - if (DEVEL) console.error(`[${this.moduleName}]`, ...args); - } - - /* eslint-enable no-console */ -} - -// --------------------------------------------------------------------------