@tech4good/platform-logging 0.1.0-alpha.0 → 0.2.0-alpha.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -1,176 +1,142 @@
|
|
|
1
|
-
import * as i0 from
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
1
|
+
import * as i0 from "@angular/core";
|
|
2
|
+
import { DestroyRef, Injectable, InjectionToken, inject, makeEnvironmentProviders, provideEnvironmentInitializer, signal } from "@angular/core";
|
|
3
|
+
const NOOP_LOGGER = Object.freeze({
|
|
4
|
+
log() {},
|
|
5
|
+
warn() {},
|
|
6
|
+
error() {}
|
|
7
|
+
});
|
|
7
8
|
const CONSOLE_LOG_SINK = ({ namespace, level, values }) => {
|
|
8
|
-
|
|
9
|
+
console[level](`[${namespace}]`, ...values);
|
|
9
10
|
};
|
|
10
|
-
|
|
11
|
-
// Internal configuration token. Consumers configure it through providePlatformLogging.
|
|
12
|
-
const PLATFORM_LOGGING_OPTIONS = new InjectionToken('PlatformLoggingOptions');
|
|
11
|
+
const PLATFORM_LOGGING_OPTIONS = new InjectionToken("PlatformLoggingOptions");
|
|
13
12
|
function selection(value) {
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
if (typeof value === 'string' && names.length === 0 || names.includes('*') || names.includes('true'))
|
|
20
|
-
return true;
|
|
21
|
-
return names.length ? [...new Set(names)] : false;
|
|
22
|
-
}
|
|
23
|
-
/**
|
|
24
|
-
* Injector-owned logging state shared by scoped loggers in that injector.
|
|
25
|
-
* Without configuration it is silent and touches no browser storage/global.
|
|
26
|
-
* Loggers capture this instance, so creating a second app or test cannot redirect
|
|
27
|
-
* an existing logger. Browser persistence and DevTools exposure are optional.
|
|
28
|
-
*
|
|
29
|
-
* With exposeDebugConsole: true in providePlatformLogging, the browser's DevTools
|
|
30
|
-
* console can control logging at runtime:
|
|
31
|
-
* - Enable all logs: debugLogger.enable()
|
|
32
|
-
* - Enable specific namespaces: debugLogger.enable('data,auth')
|
|
33
|
-
* - Disable logs: debugLogger.disable()
|
|
34
|
-
* - Toggle logs: debugLogger.toggle()
|
|
35
|
-
* Set persist: true as well if those choices should survive a page reload.
|
|
36
|
-
*/
|
|
37
|
-
class LoggingService {
|
|
38
|
-
options = inject(PLATFORM_LOGGING_OPTIONS, { optional: true }) ?? {};
|
|
39
|
-
destroyRef = inject(DestroyRef);
|
|
40
|
-
namespaces = signal(selection(this.options.enabled ?? false), ...(ngDevMode ? [{ debugName: "namespaces" }] : /* istanbul ignore next */ []));
|
|
41
|
-
sink = this.options.sink ?? CONSOLE_LOG_SINK;
|
|
42
|
-
storageKey = this.options.storageKey ?? 'debug_logs';
|
|
43
|
-
destroyed = false;
|
|
44
|
-
constructor() {
|
|
45
|
-
if (this.options.persist) {
|
|
46
|
-
try {
|
|
47
|
-
const saved = typeof window === 'undefined' ? null : window.localStorage.getItem(this.storageKey);
|
|
48
|
-
if (saved !== null)
|
|
49
|
-
this.namespaces.set(selection(saved));
|
|
50
|
-
}
|
|
51
|
-
catch {
|
|
52
|
-
// Browser storage can be unavailable; in-memory configuration still works.
|
|
53
|
-
}
|
|
54
|
-
}
|
|
55
|
-
this.destroyRef.onDestroy(() => { this.destroyed = true; });
|
|
56
|
-
this.exposeDebugConsole();
|
|
57
|
-
}
|
|
58
|
-
/**
|
|
59
|
-
* Get a logger usable after leaving an injection context, including callbacks.
|
|
60
|
-
* A namespace is an exact category name, such as data, auth or onboarding.
|
|
61
|
-
* Existing scoped loggers observe enable/disable changes without being recreated.
|
|
62
|
-
*/
|
|
63
|
-
scoped(namespace) {
|
|
64
|
-
if (!namespace || namespace.trim() !== namespace || namespace.includes(',') || ['*', 'true', 'false'].includes(namespace)) {
|
|
65
|
-
throw new Error('Logger namespaces must be nonempty names without commas or reserved filter values.');
|
|
66
|
-
}
|
|
67
|
-
return {
|
|
68
|
-
log: (...values) => this.write(namespace, 'log', values),
|
|
69
|
-
warn: (...values) => this.write(namespace, 'warn', values),
|
|
70
|
-
error: (...values) => this.write(namespace, 'error', values),
|
|
71
|
-
};
|
|
72
|
-
}
|
|
73
|
-
/** Enable all output, or exact comma-separated/array namespace names. */
|
|
74
|
-
enable(namespaces = '*') {
|
|
75
|
-
this.namespaces.set(selection(namespaces));
|
|
76
|
-
this.persist();
|
|
77
|
-
}
|
|
78
|
-
/** Disable every level, including warnings/errors, and persist that choice when enabled. */
|
|
79
|
-
disable() {
|
|
80
|
-
this.namespaces.set(false);
|
|
81
|
-
this.persist();
|
|
82
|
-
}
|
|
83
|
-
/** Toggle between disabled and all namespaces. */
|
|
84
|
-
toggle() { if (this.isEnabled())
|
|
85
|
-
this.disable();
|
|
86
|
-
else
|
|
87
|
-
this.enable(); }
|
|
88
|
-
/** Reactive read of global enablement, or whether a particular namespace is enabled. */
|
|
89
|
-
isEnabled(namespace) {
|
|
90
|
-
if (this.destroyed)
|
|
91
|
-
return false;
|
|
92
|
-
const current = this.namespaces();
|
|
93
|
-
return current === true || Array.isArray(current) && (namespace === undefined || current.includes(namespace));
|
|
94
|
-
}
|
|
95
|
-
write(namespace, level, values) {
|
|
96
|
-
if (!this.isEnabled(namespace))
|
|
97
|
-
return;
|
|
98
|
-
try {
|
|
99
|
-
this.sink({ namespace, level, values });
|
|
100
|
-
}
|
|
101
|
-
catch {
|
|
102
|
-
// Diagnostics are best effort. A failing sink must not fail the app operation
|
|
103
|
-
// being logged, or recursively call the same failing destination.
|
|
104
|
-
}
|
|
105
|
-
}
|
|
106
|
-
persist() {
|
|
107
|
-
if (!this.options.persist || this.destroyed)
|
|
108
|
-
return;
|
|
109
|
-
try {
|
|
110
|
-
if (typeof window === 'undefined')
|
|
111
|
-
return;
|
|
112
|
-
const current = this.namespaces();
|
|
113
|
-
window.localStorage.setItem(this.storageKey, typeof current === 'boolean' ? String(current) : current.join(','));
|
|
114
|
-
}
|
|
115
|
-
catch {
|
|
116
|
-
// Retain the in-memory setting even if storage is denied or full.
|
|
117
|
-
}
|
|
118
|
-
}
|
|
119
|
-
exposeDebugConsole() {
|
|
120
|
-
if (!this.options.exposeDebugConsole || typeof window === 'undefined')
|
|
121
|
-
return;
|
|
122
|
-
try {
|
|
123
|
-
// This is only a debugging handle; scoped loggers never read it. Do not
|
|
124
|
-
// replace another app's handle, and remove ours when this injector dies.
|
|
125
|
-
if ('debugLogger' in window)
|
|
126
|
-
return;
|
|
127
|
-
const target = window;
|
|
128
|
-
Object.defineProperty(target, 'debugLogger', { value: this, configurable: true, writable: true });
|
|
129
|
-
this.destroyRef.onDestroy(() => {
|
|
130
|
-
if (target['debugLogger'] === this)
|
|
131
|
-
delete target['debugLogger'];
|
|
132
|
-
});
|
|
133
|
-
}
|
|
134
|
-
catch {
|
|
135
|
-
// Nonextensible browser globals must not prevent app initialization.
|
|
136
|
-
}
|
|
137
|
-
}
|
|
138
|
-
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.2.23", ngImport: i0, type: LoggingService, deps: [], target: i0.ɵɵFactoryTarget.Injectable });
|
|
139
|
-
static ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "21.2.23", ngImport: i0, type: LoggingService, providedIn: 'root' });
|
|
13
|
+
if (typeof value === "boolean") return value;
|
|
14
|
+
if (typeof value === "string" && value === "false") return false;
|
|
15
|
+
const names = (typeof value === "string" ? value.split(",") : [...value]).map((name) => name.trim()).filter(Boolean);
|
|
16
|
+
if (typeof value === "string" && names.length === 0 || names.includes("*") || names.includes("true")) return true;
|
|
17
|
+
return names.length ? [...new Set(names)] : false;
|
|
140
18
|
}
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
19
|
+
var LoggingService = class LoggingService {
|
|
20
|
+
options = inject(PLATFORM_LOGGING_OPTIONS, { optional: true }) ?? {};
|
|
21
|
+
destroyRef = inject(DestroyRef);
|
|
22
|
+
namespaces = signal(selection(this.options.enabled ?? false), ...ngDevMode ? [{ debugName: "namespaces" }] : /* istanbul ignore next */ []);
|
|
23
|
+
sink = this.options.sink ?? CONSOLE_LOG_SINK;
|
|
24
|
+
storageKey = this.options.storageKey ?? "debug_logs";
|
|
25
|
+
destroyed = false;
|
|
26
|
+
constructor() {
|
|
27
|
+
if (this.options.persist) try {
|
|
28
|
+
const saved = typeof window === "undefined" ? null : window.localStorage.getItem(this.storageKey);
|
|
29
|
+
if (saved !== null) this.namespaces.set(selection(saved));
|
|
30
|
+
} catch {}
|
|
31
|
+
this.destroyRef.onDestroy(() => {
|
|
32
|
+
this.destroyed = true;
|
|
33
|
+
});
|
|
34
|
+
this.exposeDebugConsole();
|
|
35
|
+
}
|
|
36
|
+
scoped(namespace) {
|
|
37
|
+
if (!namespace || namespace.trim() !== namespace || namespace.includes(",") || [
|
|
38
|
+
"*",
|
|
39
|
+
"true",
|
|
40
|
+
"false"
|
|
41
|
+
].includes(namespace)) throw new Error("Logger namespaces must be nonempty names without commas or reserved filter values.");
|
|
42
|
+
return {
|
|
43
|
+
log: (...values) => this.write(namespace, "log", values),
|
|
44
|
+
warn: (...values) => this.write(namespace, "warn", values),
|
|
45
|
+
error: (...values) => this.write(namespace, "error", values)
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
enable(namespaces = "*") {
|
|
49
|
+
this.namespaces.set(selection(namespaces));
|
|
50
|
+
this.persist();
|
|
51
|
+
}
|
|
52
|
+
disable() {
|
|
53
|
+
this.namespaces.set(false);
|
|
54
|
+
this.persist();
|
|
55
|
+
}
|
|
56
|
+
toggle() {
|
|
57
|
+
if (this.isEnabled()) this.disable();
|
|
58
|
+
else this.enable();
|
|
59
|
+
}
|
|
60
|
+
isEnabled(namespace) {
|
|
61
|
+
if (this.destroyed) return false;
|
|
62
|
+
const current = this.namespaces();
|
|
63
|
+
return current === true || Array.isArray(current) && (namespace === void 0 || current.includes(namespace));
|
|
64
|
+
}
|
|
65
|
+
write(namespace, level, values) {
|
|
66
|
+
if (!this.isEnabled(namespace)) return;
|
|
67
|
+
try {
|
|
68
|
+
this.sink({
|
|
69
|
+
namespace,
|
|
70
|
+
level,
|
|
71
|
+
values
|
|
72
|
+
});
|
|
73
|
+
} catch {}
|
|
74
|
+
}
|
|
75
|
+
persist() {
|
|
76
|
+
if (!this.options.persist || this.destroyed) return;
|
|
77
|
+
try {
|
|
78
|
+
if (typeof window === "undefined") return;
|
|
79
|
+
const current = this.namespaces();
|
|
80
|
+
window.localStorage.setItem(this.storageKey, typeof current === "boolean" ? String(current) : current.join(","));
|
|
81
|
+
} catch {}
|
|
82
|
+
}
|
|
83
|
+
exposeDebugConsole() {
|
|
84
|
+
if (!this.options.exposeDebugConsole || typeof window === "undefined") return;
|
|
85
|
+
try {
|
|
86
|
+
if ("debugLogger" in window) return;
|
|
87
|
+
const target = window;
|
|
88
|
+
Object.defineProperty(target, "debugLogger", {
|
|
89
|
+
value: this,
|
|
90
|
+
configurable: true,
|
|
91
|
+
writable: true
|
|
92
|
+
});
|
|
93
|
+
this.destroyRef.onDestroy(() => {
|
|
94
|
+
if (target["debugLogger"] === this) delete target["debugLogger"];
|
|
95
|
+
});
|
|
96
|
+
} catch {}
|
|
97
|
+
}
|
|
98
|
+
static ɵfac = i0.ɵɵngDeclareFactory({
|
|
99
|
+
minVersion: "12.0.0",
|
|
100
|
+
version: "22.3.0",
|
|
101
|
+
ngImport: i0,
|
|
102
|
+
type: LoggingService,
|
|
103
|
+
deps: [],
|
|
104
|
+
target: i0.ɵɵFactoryTarget.Injectable
|
|
105
|
+
});
|
|
106
|
+
static ɵprov = i0.ɵɵngDeclareInjectable({
|
|
107
|
+
minVersion: "12.0.0",
|
|
108
|
+
version: "22.3.0",
|
|
109
|
+
ngImport: i0,
|
|
110
|
+
type: LoggingService,
|
|
111
|
+
providedIn: "root"
|
|
112
|
+
});
|
|
113
|
+
};
|
|
114
|
+
i0.ɵɵngDeclareClassMetadata({
|
|
115
|
+
minVersion: "12.0.0",
|
|
116
|
+
version: "22.3.0",
|
|
117
|
+
ngImport: i0,
|
|
118
|
+
type: LoggingService,
|
|
119
|
+
decorators: [{
|
|
120
|
+
type: Injectable,
|
|
121
|
+
args: [{ providedIn: "root" }]
|
|
122
|
+
}],
|
|
123
|
+
ctorParameters: () => []
|
|
124
|
+
});
|
|
151
125
|
function injectLogger(namespace) {
|
|
152
|
-
|
|
126
|
+
return inject(LoggingService).scoped(namespace);
|
|
153
127
|
}
|
|
154
|
-
|
|
155
|
-
/**
|
|
156
|
-
* Configure logging once at the application's root. Supplying this provider in
|
|
157
|
-
* another environment injector creates independent logging state there.
|
|
158
|
-
* Initialization eagerly restores settings/exposes optional DevTools controls,
|
|
159
|
-
* even before any feature requests a logger. All browser features are opt-in.
|
|
160
|
-
*/
|
|
161
128
|
function providePlatformLogging(options = {}) {
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
129
|
+
return makeEnvironmentProviders([
|
|
130
|
+
{
|
|
131
|
+
provide: PLATFORM_LOGGING_OPTIONS,
|
|
132
|
+
useValue: options
|
|
133
|
+
},
|
|
134
|
+
LoggingService,
|
|
135
|
+
provideEnvironmentInitializer(() => {
|
|
136
|
+
inject(LoggingService);
|
|
137
|
+
})
|
|
138
|
+
]);
|
|
167
139
|
}
|
|
168
|
-
|
|
169
|
-
/** Shared runtime logging. No data, Firebase, Material or Node tooling dependency. */
|
|
170
|
-
|
|
171
|
-
/**
|
|
172
|
-
* Generated bundle index. Do not edit.
|
|
173
|
-
*/
|
|
174
|
-
|
|
175
140
|
export { CONSOLE_LOG_SINK, LoggingService, NOOP_LOGGER, injectLogger, providePlatformLogging };
|
|
176
|
-
|
|
141
|
+
|
|
142
|
+
//# sourceMappingURL=tech4good-platform-logging.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"tech4good-platform-logging.mjs","sources":["../../src/logger.ts","../../src/logging.service.ts","../../src/providers.ts","../../src/public-api.ts","../../src/tech4good-platform-logging.ts"],"sourcesContent":["/** A namespace-bound logger. Arguments retain their original values for the output sink. */\nexport interface Logger {\n log(...values: unknown[]): void;\n warn(...values: unknown[]): void;\n error(...values: unknown[]): void;\n}\n\nexport type LogLevel = 'log' | 'warn' | 'error';\n\n/** One accepted log call, after namespace filtering. No serialization is imposed. */\nexport interface LogEntry {\n readonly namespace: string;\n readonly level: LogLevel;\n readonly values: readonly unknown[];\n}\n\n/** Synchronous destination for messages. Applications can queue remote delivery here. */\nexport type LogSink = (entry: LogEntry) => void;\n\n/** Useful when constructing non-injectable helpers without diagnostic output. */\nexport const NOOP_LOGGER: Logger = Object.freeze({ log() {}, warn() {}, error() {} });\n\n/** Default browser/server console destination, retaining namespace and argument structure. */\nexport const CONSOLE_LOG_SINK: LogSink = ({ namespace, level, values }) => {\n console[level](`[${namespace}]`, ...values);\n};\n","import { DestroyRef, Injectable, InjectionToken, inject, signal } from '@angular/core';\nimport { CONSOLE_LOG_SINK, Logger, LogLevel, LogSink } from './logger';\n\n/** Configuration belongs to the application; the package never imports app environments. */\nexport interface PlatformLoggingOptions {\n /** False by default; true enables all namespaces, an array enables exact names. */\n enabled?: boolean | readonly string[];\n /** Replace console output with an application-owned destination. */\n sink?: LogSink;\n /** Restore/save namespace settings in browser localStorage. Off by default. */\n persist?: boolean;\n /** Use separate keys for apps sharing an origin. Defaults to debug_logs. */\n storageKey?: string;\n /** Opt in to window.debugLogger controls; normally enabled only in development. */\n exposeDebugConsole?: boolean;\n}\n\n// Internal configuration token. Consumers configure it through providePlatformLogging.\nexport const PLATFORM_LOGGING_OPTIONS = new InjectionToken<PlatformLoggingOptions>('PlatformLoggingOptions');\n\ntype NamespaceSelection = boolean | readonly string[];\n\nfunction selection(value: boolean | string | readonly string[]): NamespaceSelection {\n if (typeof value === 'boolean') return value;\n if (typeof value === 'string' && value === 'false') return false;\n const names = (typeof value === 'string' ? value.split(',') : [...value]).map(name => name.trim()).filter(Boolean);\n if (typeof value === 'string' && names.length === 0 || names.includes('*') || names.includes('true')) return true;\n return names.length ? [...new Set(names)] : false;\n}\n\n/**\n * Injector-owned logging state shared by scoped loggers in that injector.\n * Without configuration it is silent and touches no browser storage/global.\n * Loggers capture this instance, so creating a second app or test cannot redirect\n * an existing logger. Browser persistence and DevTools exposure are optional.\n *\n * With exposeDebugConsole: true in providePlatformLogging, the browser's DevTools\n * console can control logging at runtime:\n * - Enable all logs: debugLogger.enable()\n * - Enable specific namespaces: debugLogger.enable('data,auth')\n * - Disable logs: debugLogger.disable()\n * - Toggle logs: debugLogger.toggle()\n * Set persist: true as well if those choices should survive a page reload.\n */\n@Injectable({ providedIn: 'root' })\nexport class LoggingService {\n private readonly options = inject(PLATFORM_LOGGING_OPTIONS, { optional: true }) ?? {};\n private readonly destroyRef = inject(DestroyRef);\n private readonly namespaces = signal<NamespaceSelection>(selection(this.options.enabled ?? false));\n private readonly sink = this.options.sink ?? CONSOLE_LOG_SINK;\n private readonly storageKey = this.options.storageKey ?? 'debug_logs';\n private destroyed = false;\n\n constructor() {\n if (this.options.persist) {\n try {\n const saved = typeof window === 'undefined' ? null : window.localStorage.getItem(this.storageKey);\n if (saved !== null) this.namespaces.set(selection(saved));\n } catch {\n // Browser storage can be unavailable; in-memory configuration still works.\n }\n }\n this.destroyRef.onDestroy(() => { this.destroyed = true; });\n this.exposeDebugConsole();\n }\n\n /**\n * Get a logger usable after leaving an injection context, including callbacks.\n * A namespace is an exact category name, such as data, auth or onboarding.\n * Existing scoped loggers observe enable/disable changes without being recreated.\n */\n scoped(namespace: string): Logger {\n if (!namespace || namespace.trim() !== namespace || namespace.includes(',') || ['*', 'true', 'false'].includes(namespace)) {\n throw new Error('Logger namespaces must be nonempty names without commas or reserved filter values.');\n }\n return {\n log: (...values) => this.write(namespace, 'log', values),\n warn: (...values) => this.write(namespace, 'warn', values),\n error: (...values) => this.write(namespace, 'error', values),\n };\n }\n\n /** Enable all output, or exact comma-separated/array namespace names. */\n enable(namespaces: string | readonly string[] = '*'): void {\n this.namespaces.set(selection(namespaces));\n this.persist();\n }\n\n /** Disable every level, including warnings/errors, and persist that choice when enabled. */\n disable(): void {\n this.namespaces.set(false);\n this.persist();\n }\n\n /** Toggle between disabled and all namespaces. */\n toggle(): void { if (this.isEnabled()) this.disable(); else this.enable(); }\n\n /** Reactive read of global enablement, or whether a particular namespace is enabled. */\n isEnabled(namespace?: string): boolean {\n if (this.destroyed) return false;\n const current = this.namespaces();\n return current === true || Array.isArray(current) && (namespace === undefined || current.includes(namespace));\n }\n\n private write(namespace: string, level: LogLevel, values: unknown[]): void {\n if (!this.isEnabled(namespace)) return;\n try { this.sink({ namespace, level, values }); }\n catch {\n // Diagnostics are best effort. A failing sink must not fail the app operation\n // being logged, or recursively call the same failing destination.\n }\n }\n\n private persist(): void {\n if (!this.options.persist || this.destroyed) return;\n try {\n if (typeof window === 'undefined') return;\n const current = this.namespaces();\n window.localStorage.setItem(this.storageKey, typeof current === 'boolean' ? String(current) : current.join(','));\n } catch {\n // Retain the in-memory setting even if storage is denied or full.\n }\n }\n\n private exposeDebugConsole(): void {\n if (!this.options.exposeDebugConsole || typeof window === 'undefined') return;\n try {\n // This is only a debugging handle; scoped loggers never read it. Do not\n // replace another app's handle, and remove ours when this injector dies.\n if ('debugLogger' in window) return;\n const target = window as unknown as Record<string, unknown>;\n Object.defineProperty(target, 'debugLogger', { value: this, configurable: true, writable: true });\n this.destroyRef.onDestroy(() => {\n if (target['debugLogger'] === this) delete target['debugLogger'];\n });\n } catch {\n // Nonextensible browser globals must not prevent app initialization.\n }\n }\n}\n\n/**\n * Request a scoped logger in an Angular injection context, such as a field\n * initializer or provider factory. Retain it for later event/async callbacks.\n * @example\n * private readonly logger = injectLogger('auth');\n */\nexport function injectLogger(namespace: string): Logger {\n return inject(LoggingService).scoped(namespace);\n}\n","import { EnvironmentProviders, inject, makeEnvironmentProviders, provideEnvironmentInitializer } from '@angular/core';\nimport { LoggingService, PLATFORM_LOGGING_OPTIONS, PlatformLoggingOptions } from './logging.service';\n\n/**\n * Configure logging once at the application's root. Supplying this provider in\n * another environment injector creates independent logging state there.\n * Initialization eagerly restores settings/exposes optional DevTools controls,\n * even before any feature requests a logger. All browser features are opt-in.\n */\nexport function providePlatformLogging(options: PlatformLoggingOptions = {}): EnvironmentProviders {\n return makeEnvironmentProviders([\n { provide: PLATFORM_LOGGING_OPTIONS, useValue: options },\n LoggingService,\n provideEnvironmentInitializer(() => { inject(LoggingService); }),\n ]);\n}\n","/** Shared runtime logging. No data, Firebase, Material or Node tooling dependency. */\nexport * from './logger';\nexport { LoggingService, injectLogger } from './logging.service';\nexport type { PlatformLoggingOptions } from './logging.service';\nexport { providePlatformLogging } from './providers';\n","/**\n * Generated bundle index. Do not edit.\n */\n\nexport * from './public-api';\n"],"names":[],"mappings":";;;AAmBA;MACa,WAAW,GAAW,MAAM,CAAC,MAAM,CAAC,EAAE,GAAG,GAAA,EAAI,CAAC,EAAE,IAAI,KAAI,CAAC,EAAE,KAAK,GAAA,EAAI,CAAC,EAAE;AAEpF;AACO,MAAM,gBAAgB,GAAY,CAAC,EAAE,SAAS,EAAE,KAAK,EAAE,MAAM,EAAE,KAAI;IACxE,OAAO,CAAC,KAAK,CAAC,CAAC,CAAA,CAAA,EAAI,SAAS,CAAA,CAAA,CAAG,EAAE,GAAG,MAAM,CAAC;AAC7C;;ACRA;AACO,MAAM,wBAAwB,GAAG,IAAI,cAAc,CAAyB,wBAAwB,CAAC;AAI5G,SAAS,SAAS,CAAC,KAA2C,EAAA;IAC5D,IAAI,OAAO,KAAK,KAAK,SAAS;AAAE,QAAA,OAAO,KAAK;AAC5C,IAAA,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,KAAK,OAAO;AAAE,QAAA,OAAO,KAAK;AAChE,IAAA,MAAM,KAAK,GAAG,CAAC,OAAO,KAAK,KAAK,QAAQ,GAAG,KAAK,CAAC,KAAK,CAAC,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,KAAK,EAAE,IAAI,EAAE,YAAY,EAAE,IAAI,EAAE,QAAQ,EAAE,IAAI,EAAE,CAAC;AACjG,YAAA,IAAI,CAAC,UAAU,CAAC,SAAS,CAAC,MAAK;AAC7B,gBAAA,IAAI,MAAM,CAAC,aAAa,CAAC,KAAK,IAAI;AAAE,oBAAA,OAAO,MAAM,CAAC,aAAa,CAAC;AAClE,YAAA,CAAC,CAAC;QACJ;AAAE,QAAA,MAAM;;QAER;IACF;wGA7FW,cAAc,EAAA,IAAA,EAAA,EAAA,EAAA,MAAA,EAAA,EAAA,CAAA,eAAA,CAAA,UAAA,EAAA,CAAA;AAAd,IAAA,OAAA,KAAA,GAAA,EAAA,CAAA,qBAAA,CAAA,EAAA,UAAA,EAAA,QAAA,EAAA,OAAA,EAAA,SAAA,EAAA,QAAA,EAAA,EAAA,EAAA,IAAA,EAAA,cAAc,cADD,MAAM,EAAA,CAAA;;4FACnB,cAAc,EAAA,UAAA,EAAA,CAAA;kBAD1B,UAAU;mBAAC,EAAE,UAAU,EAAE,MAAM,EAAE;;AAiGlC;;;;;AAKG;AACG,SAAU,YAAY,CAAC,SAAiB,EAAA;IAC5C,OAAO,MAAM,CAAC,cAAc,CAAC,CAAC,MAAM,CAAC,SAAS,CAAC;AACjD;;AClJA;;;;;AAKG;AACG,SAAU,sBAAsB,CAAC,OAAA,GAAkC,EAAE,EAAA;AACzE,IAAA,OAAO,wBAAwB,CAAC;AAC9B,QAAA,EAAE,OAAO,EAAE,wBAAwB,EAAE,QAAQ,EAAE,OAAO,EAAE;QACxD,cAAc;QACd,6BAA6B,CAAC,MAAK,EAAG,MAAM,CAAC,cAAc,CAAC,CAAC,CAAC,CAAC,CAAC;AACjE,KAAA,CAAC;AACJ;;ACfA;;ACAA;;AAEG;;"}
|
|
1
|
+
{"version":3,"file":"tech4good-platform-logging.mjs","names":[],"sources":["../../src/logger.ts","../../src/logging.service.ts","../../src/providers.ts"],"sourcesContent":["/** A namespace-bound logger. Arguments retain their original values for the output sink. */\nexport interface Logger {\n log(...values: unknown[]): void;\n warn(...values: unknown[]): void;\n error(...values: unknown[]): void;\n}\n\nexport type LogLevel = 'log' | 'warn' | 'error';\n\n/** One accepted log call, after namespace filtering. No serialization is imposed. */\nexport interface LogEntry {\n readonly namespace: string;\n readonly level: LogLevel;\n readonly values: readonly unknown[];\n}\n\n/** Synchronous destination for messages. Applications can queue remote delivery here. */\nexport type LogSink = (entry: LogEntry) => void;\n\n/** Useful when constructing non-injectable helpers without diagnostic output. */\nexport const NOOP_LOGGER: Logger = Object.freeze({ log() {}, warn() {}, error() {} });\n\n/** Default browser/server console destination, retaining namespace and argument structure. */\nexport const CONSOLE_LOG_SINK: LogSink = ({ namespace, level, values }) => {\n console[level](`[${namespace}]`, ...values);\n};\n","import { DestroyRef, Injectable, InjectionToken, inject, signal } from '@angular/core';\nimport { CONSOLE_LOG_SINK, Logger, LogLevel, LogSink } from './logger';\n\n/** Configuration belongs to the application; the package never imports app environments. */\nexport interface PlatformLoggingOptions {\n /** False by default; true enables all namespaces, an array enables exact names. */\n enabled?: boolean | readonly string[];\n /** Replace console output with an application-owned destination. */\n sink?: LogSink;\n /** Restore/save namespace settings in browser localStorage. Off by default. */\n persist?: boolean;\n /** Use separate keys for apps sharing an origin. Defaults to debug_logs. */\n storageKey?: string;\n /** Opt in to window.debugLogger controls; normally enabled only in development. */\n exposeDebugConsole?: boolean;\n}\n\n// Internal configuration token. Consumers configure it through providePlatformLogging.\nexport const PLATFORM_LOGGING_OPTIONS = new InjectionToken<PlatformLoggingOptions>('PlatformLoggingOptions');\n\ntype NamespaceSelection = boolean | readonly string[];\n\nfunction selection(value: boolean | string | readonly string[]): NamespaceSelection {\n if (typeof value === 'boolean') return value;\n if (typeof value === 'string' && value === 'false') return false;\n const names = (typeof value === 'string' ? value.split(',') : [...value]).map(name => name.trim()).filter(Boolean);\n if (typeof value === 'string' && names.length === 0 || names.includes('*') || names.includes('true')) return true;\n return names.length ? [...new Set(names)] : false;\n}\n\n/**\n * Injector-owned logging state shared by scoped loggers in that injector.\n * Without configuration it is silent and touches no browser storage/global.\n * Loggers capture this instance, so creating a second app or test cannot redirect\n * an existing logger. Browser persistence and DevTools exposure are optional.\n *\n * With exposeDebugConsole: true in providePlatformLogging, the browser's DevTools\n * console can control logging at runtime:\n * - Enable all logs: debugLogger.enable()\n * - Enable specific namespaces: debugLogger.enable('data,auth')\n * - Disable logs: debugLogger.disable()\n * - Toggle logs: debugLogger.toggle()\n * Set persist: true as well if those choices should survive a page reload.\n */\n@Injectable({ providedIn: 'root' })\nexport class LoggingService {\n private readonly options = inject(PLATFORM_LOGGING_OPTIONS, { optional: true }) ?? {};\n private readonly destroyRef = inject(DestroyRef);\n private readonly namespaces = signal<NamespaceSelection>(selection(this.options.enabled ?? false));\n private readonly sink = this.options.sink ?? CONSOLE_LOG_SINK;\n private readonly storageKey = this.options.storageKey ?? 'debug_logs';\n private destroyed = false;\n\n constructor() {\n if (this.options.persist) {\n try {\n const saved = typeof window === 'undefined' ? null : window.localStorage.getItem(this.storageKey);\n if (saved !== null) this.namespaces.set(selection(saved));\n } catch {\n // Browser storage can be unavailable; in-memory configuration still works.\n }\n }\n this.destroyRef.onDestroy(() => { this.destroyed = true; });\n this.exposeDebugConsole();\n }\n\n /**\n * Get a logger usable after leaving an injection context, including callbacks.\n * A namespace is an exact category name, such as data, auth or onboarding.\n * Existing scoped loggers observe enable/disable changes without being recreated.\n */\n scoped(namespace: string): Logger {\n if (!namespace || namespace.trim() !== namespace || namespace.includes(',') || ['*', 'true', 'false'].includes(namespace)) {\n throw new Error('Logger namespaces must be nonempty names without commas or reserved filter values.');\n }\n return {\n log: (...values) => this.write(namespace, 'log', values),\n warn: (...values) => this.write(namespace, 'warn', values),\n error: (...values) => this.write(namespace, 'error', values),\n };\n }\n\n /** Enable all output, or exact comma-separated/array namespace names. */\n enable(namespaces: string | readonly string[] = '*'): void {\n this.namespaces.set(selection(namespaces));\n this.persist();\n }\n\n /** Disable every level, including warnings/errors, and persist that choice when enabled. */\n disable(): void {\n this.namespaces.set(false);\n this.persist();\n }\n\n /** Toggle between disabled and all namespaces. */\n toggle(): void { if (this.isEnabled()) this.disable(); else this.enable(); }\n\n /** Reactive read of global enablement, or whether a particular namespace is enabled. */\n isEnabled(namespace?: string): boolean {\n if (this.destroyed) return false;\n const current = this.namespaces();\n return current === true || Array.isArray(current) && (namespace === undefined || current.includes(namespace));\n }\n\n private write(namespace: string, level: LogLevel, values: unknown[]): void {\n if (!this.isEnabled(namespace)) return;\n try { this.sink({ namespace, level, values }); }\n catch {\n // Diagnostics are best effort. A failing sink must not fail the app operation\n // being logged, or recursively call the same failing destination.\n }\n }\n\n private persist(): void {\n if (!this.options.persist || this.destroyed) return;\n try {\n if (typeof window === 'undefined') return;\n const current = this.namespaces();\n window.localStorage.setItem(this.storageKey, typeof current === 'boolean' ? String(current) : current.join(','));\n } catch {\n // Retain the in-memory setting even if storage is denied or full.\n }\n }\n\n private exposeDebugConsole(): void {\n if (!this.options.exposeDebugConsole || typeof window === 'undefined') return;\n try {\n // This is only a debugging handle; scoped loggers never read it. Do not\n // replace another app's handle, and remove ours when this injector dies.\n if ('debugLogger' in window) return;\n const target = window as unknown as Record<string, unknown>;\n Object.defineProperty(target, 'debugLogger', { value: this, configurable: true, writable: true });\n this.destroyRef.onDestroy(() => {\n if (target['debugLogger'] === this) delete target['debugLogger'];\n });\n } catch {\n // Nonextensible browser globals must not prevent app initialization.\n }\n }\n}\n\n/**\n * Request a scoped logger in an Angular injection context, such as a field\n * initializer or provider factory. Retain it for later event/async callbacks.\n * @example\n * private readonly logger = injectLogger('auth');\n */\nexport function injectLogger(namespace: string): Logger {\n return inject(LoggingService).scoped(namespace);\n}\n","import { EnvironmentProviders, inject, makeEnvironmentProviders, provideEnvironmentInitializer } from '@angular/core';\nimport { LoggingService, PLATFORM_LOGGING_OPTIONS, PlatformLoggingOptions } from './logging.service';\n\n/**\n * Configure logging once at the application's root. Supplying this provider in\n * another environment injector creates independent logging state there.\n * Initialization eagerly restores settings/exposes optional DevTools controls,\n * even before any feature requests a logger. All browser features are opt-in.\n */\nexport function providePlatformLogging(options: PlatformLoggingOptions = {}): EnvironmentProviders {\n return makeEnvironmentProviders([\n { provide: PLATFORM_LOGGING_OPTIONS, useValue: options },\n LoggingService,\n provideEnvironmentInitializer(() => { inject(LoggingService); }),\n ]);\n}\n"],"mappings":";;AAoBA,MAAa,cAAsB,OAAO,OAAO;CAAE,MAAG,CAAI;CAAG,OAAI,CAAI;CAAG,QAAK,CAAI;AAAC,CAAE;AAGpF,MAAa,oBAA6B,EAAE,WAAW,OAAO,aAAY;CACxE,QAAQ,MAAM,CAAC,IAAI,UAAS,IAAK,GAAG,MAAM;AAC5C;ACPA,MAAa,2BAA2B,IAAI,eAAuC,wBAAwB;AAI3G,SAAS,UAAU,OAA2C;CAC5D,IAAI,OAAO,UAAU,WAAW,OAAO;CACvC,IAAI,OAAO,UAAU,YAAY,UAAU,SAAS,OAAO;CAC3D,MAAM,SAAS,OAAO,UAAU,WAAW,MAAM,MAAM,GAAG,IAAI,CAAC,GAAG,KAAK,EAAA,CAAG,KAAI,SAAQ,KAAK,KAAI,CAAE,CAAC,CAAC,OAAO,OAAO;CACjH,IAAI,OAAO,UAAU,YAAY,MAAM,WAAW,KAAK,MAAM,SAAS,GAAG,KAAK,MAAM,SAAS,MAAM,GAAG,OAAO;CAC7G,OAAO,MAAM,SAAS,CAAC,GAAG,IAAI,IAAI,KAAK,CAAC,IAAI;AAC9C;AAiBA,IAAa,iBAAb,MAAa,eAAc;CACR,UAAU,OAAO,0BAA0B,EAAE,UAAU,KAAI,CAAE,KAAK,CAAA;CAClE,aAAa,OAAO,UAAU;CAC9B,aAAa,OAA2B,UAAU,KAAK,QAAQ,WAAW,KAAK,GAAE,GAAA,YAAA,CAAA,EAAA,WAAA,aAAA,CAAA,+BAAA,CAAA,CAAA;CACjF,OAAO,KAAK,QAAQ,QAAQ;CAC5B,aAAa,KAAK,QAAQ,cAAc;CACjD,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
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tech4good/platform-logging",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.2.0-alpha.0",
|
|
4
4
|
"description": "Shared runtime logging and namespace controls for Tech4Good Angular applications.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"sideEffects": false,
|
|
7
7
|
"typings": "types/tech4good-platform-logging.d.ts",
|
|
8
8
|
"peerDependencies": {
|
|
9
|
-
"@angular/core": "^
|
|
9
|
+
"@angular/core": "^22.0.0"
|
|
10
10
|
},
|
|
11
11
|
"dependencies": {
|
|
12
12
|
"tslib": "^2.3.0"
|
|
@@ -1,38 +1,39 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
/**
|
|
2
|
+
* Generated bundle index. Do not edit.
|
|
3
|
+
*/
|
|
4
|
+
import * as i0 from "@angular/core";
|
|
5
|
+
import { EnvironmentProviders } from "@angular/core";
|
|
4
6
|
/** A namespace-bound logger. Arguments retain their original values for the output sink. */
|
|
5
|
-
interface Logger {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
7
|
+
export interface Logger {
|
|
8
|
+
log(...values: unknown[]): void;
|
|
9
|
+
warn(...values: unknown[]): void;
|
|
10
|
+
error(...values: unknown[]): void;
|
|
9
11
|
}
|
|
10
|
-
type LogLevel = 'log' | 'warn' | 'error';
|
|
12
|
+
export type LogLevel = 'log' | 'warn' | 'error';
|
|
11
13
|
/** One accepted log call, after namespace filtering. No serialization is imposed. */
|
|
12
|
-
interface LogEntry {
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
14
|
+
export interface LogEntry {
|
|
15
|
+
readonly namespace: string;
|
|
16
|
+
readonly level: LogLevel;
|
|
17
|
+
readonly values: readonly unknown[];
|
|
16
18
|
}
|
|
17
19
|
/** Synchronous destination for messages. Applications can queue remote delivery here. */
|
|
18
|
-
type LogSink = (entry: LogEntry) => void;
|
|
20
|
+
export type LogSink = (entry: LogEntry) => void;
|
|
19
21
|
/** Useful when constructing non-injectable helpers without diagnostic output. */
|
|
20
|
-
declare const NOOP_LOGGER: Logger;
|
|
22
|
+
export declare const NOOP_LOGGER: Logger;
|
|
21
23
|
/** Default browser/server console destination, retaining namespace and argument structure. */
|
|
22
|
-
declare const CONSOLE_LOG_SINK: LogSink;
|
|
23
|
-
|
|
24
|
+
export declare const CONSOLE_LOG_SINK: LogSink;
|
|
24
25
|
/** Configuration belongs to the application; the package never imports app environments. */
|
|
25
26
|
interface PlatformLoggingOptions {
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
27
|
+
/** False by default; true enables all namespaces, an array enables exact names. */
|
|
28
|
+
enabled?: boolean | readonly string[];
|
|
29
|
+
/** Replace console output with an application-owned destination. */
|
|
30
|
+
sink?: LogSink;
|
|
31
|
+
/** Restore/save namespace settings in browser localStorage. Off by default. */
|
|
32
|
+
persist?: boolean;
|
|
33
|
+
/** Use separate keys for apps sharing an origin. Defaults to debug_logs. */
|
|
34
|
+
storageKey?: string;
|
|
35
|
+
/** Opt in to window.debugLogger controls; normally enabled only in development. */
|
|
36
|
+
exposeDebugConsole?: boolean;
|
|
36
37
|
}
|
|
37
38
|
/**
|
|
38
39
|
* Injector-owned logging state shared by scoped loggers in that injector.
|
|
@@ -48,33 +49,33 @@ interface PlatformLoggingOptions {
|
|
|
48
49
|
* - Toggle logs: debugLogger.toggle()
|
|
49
50
|
* Set persist: true as well if those choices should survive a page reload.
|
|
50
51
|
*/
|
|
51
|
-
declare class LoggingService {
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
52
|
+
export declare class LoggingService {
|
|
53
|
+
private readonly options;
|
|
54
|
+
private readonly destroyRef;
|
|
55
|
+
private readonly namespaces;
|
|
56
|
+
private readonly sink;
|
|
57
|
+
private readonly storageKey;
|
|
58
|
+
private destroyed;
|
|
59
|
+
constructor();
|
|
60
|
+
/**
|
|
61
|
+
* Get a logger usable after leaving an injection context, including callbacks.
|
|
62
|
+
* A namespace is an exact category name, such as data, auth or onboarding.
|
|
63
|
+
* Existing scoped loggers observe enable/disable changes without being recreated.
|
|
64
|
+
*/
|
|
65
|
+
scoped(namespace: string): Logger;
|
|
66
|
+
/** Enable all output, or exact comma-separated/array namespace names. */
|
|
67
|
+
enable(namespaces?: string | readonly string[]): void;
|
|
68
|
+
/** Disable every level, including warnings/errors, and persist that choice when enabled. */
|
|
69
|
+
disable(): void;
|
|
70
|
+
/** Toggle between disabled and all namespaces. */
|
|
71
|
+
toggle(): void;
|
|
72
|
+
/** Reactive read of global enablement, or whether a particular namespace is enabled. */
|
|
73
|
+
isEnabled(namespace?: string): boolean;
|
|
74
|
+
private write;
|
|
75
|
+
private persist;
|
|
76
|
+
private exposeDebugConsole;
|
|
77
|
+
static ɵfac: i0.ɵɵFactoryDeclaration<LoggingService, never>;
|
|
78
|
+
static ɵprov: i0.ɵɵInjectableDeclaration<any>;
|
|
78
79
|
}
|
|
79
80
|
/**
|
|
80
81
|
* Request a scoped logger in an Angular injection context, such as a field
|
|
@@ -82,16 +83,13 @@ declare class LoggingService {
|
|
|
82
83
|
* @example
|
|
83
84
|
* private readonly logger = injectLogger('auth');
|
|
84
85
|
*/
|
|
85
|
-
declare function injectLogger(namespace: string): Logger;
|
|
86
|
-
|
|
86
|
+
export declare function injectLogger(namespace: string): Logger;
|
|
87
87
|
/**
|
|
88
88
|
* Configure logging once at the application's root. Supplying this provider in
|
|
89
89
|
* another environment injector creates independent logging state there.
|
|
90
90
|
* Initialization eagerly restores settings/exposes optional DevTools controls,
|
|
91
91
|
* even before any feature requests a logger. All browser features are opt-in.
|
|
92
92
|
*/
|
|
93
|
-
declare function providePlatformLogging(options?: PlatformLoggingOptions): EnvironmentProviders;
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
export type { LogEntry, LogLevel, LogSink, Logger, PlatformLoggingOptions };
|
|
97
|
-
//# sourceMappingURL=tech4good-platform-logging.d.ts.map
|
|
93
|
+
export declare function providePlatformLogging(options?: PlatformLoggingOptions): EnvironmentProviders;
|
|
94
|
+
export type { PlatformLoggingOptions };
|
|
95
|
+
//# sourceMappingURL=tech4good-platform-logging.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"tech4good-platform-logging.d.ts","sources":["../../src/logger.ts","../../src/logging.service.ts","../../src/providers.ts"],"mappings":"
|
|
1
|
+
{"version":3,"file":"tech4good-platform-logging.d.ts","names":[],"sources":["../../src/logger.ts","../../src/logging.service.ts","../../src/providers.ts"],"mappings":";;;;;;iBACiB;EACf,OAAO;EACP,QAAQ;EACR,SAAS;;YAGC;;iBAGK;WACN;WACA,OAAO;WACP;;;YAIC,WAAW,OAAO;;qBAGjB,aAAa;;qBAGb,kBAAkB;;UCnBd;;EAEf;;EAEA,OAAO;;EAEP;;EAEA;;EAEA;;;;;;;;;;;;;;;;qBA+BW;mBACM;mBACA;mBACA;mBACA;mBACA;UACT;;;;;;;EAoBR,OAAO,oBAAoB;;EAY3B,OAAO;;EAMP;;EAMA;;EAGA,UAAU;UAMF;UASA;UAWA;SA/EG,MAAA,GAAA,qBAAA;;;;;;;;;wBAsGG,aAAa,oBAAoB;;;;;;;wBC1IjC,uBAAuB,UAAS,yBAA8B"}
|