@genesislcap/foundation-logger
v15.72.0
Published
Genesis Foundation Logger
Readme
@genesislcap/foundation-logger
Documentation for this package is published on the Genesis docs site:
Docs: Utility methods
Log output
Console messages do not include an in-message timestamp by default (Chrome's DevTools clock is separate). Opt in with a live global switch so every createLogger instance, including those already created by Foundation packages, prefixes messages with local time including milliseconds (for example 11:52:03.412):
import { setLogTimestamps } from '@genesislcap/foundation-logger';
setLogTimestamps(true);The flag is stored on globalThis via Symbol.for, so one call also reaches Module Federation remotes that bundled their own copy of this package (rather than sharing the host's module).
Enable or disable the prefix on one logger only:
import { createLogger } from '@genesislcap/foundation-logger';
createLogger('demo', { timestamps: true });
createLogger('quiet', { timestamps: false });
createLogger('legacy', { formatOptions: { date: true } });Options passed to createLogger are always merged with defaultLoggerOptions. Callers that omit level therefore get debug (this package's default), not Consola's bare info default.
A default reporter is only installed in the browser. Outside the browser Consola has no default
reporter, so loggers stay silent unless you pass reporters explicitly:
import { createLogger, TimestampBrowserReporter } from '@genesislcap/foundation-logger';
createLogger('node-side', { reporters: [new TimestampBrowserReporter()] });Global log reporters
Genesis packages (foundation-comms, foundation-state-machine, etc.) report messages through their own createLogger() instances created at import time. Register a global reporter to observe logs from all foundation loggers across the application, including loggers instantiated before registration and loggers created by Module Federation remotes:
import { addGlobalLogReporter } from '@genesislcap/foundation-logger';
const unsubscribe = addGlobalLogReporter({
log: ({ type, tag, args }) => {
if (type !== 'error') return;
const error = args.find((a) => a instanceof Error);
error
? Sentry.captureException(error, { tags: { logger: tag } })
: Sentry.captureMessage(`${tag}: ${String(args[0])}`, { level: 'error' });
},
});
// Remove the reporter when no longer needed:
unsubscribe();Logged arguments can hold credentials or personal and business data, so avoid forwarding them to a third-party service. setupErrorMonitoring from @genesislcap/foundation-utils wires this up and sends only log messages and exceptions.
The reporter registry is stored on globalThis via Symbol.for, so one registration covers every runtime copy of this package that uses the same registry version. A copy built against an older registry shape keeps its own registry rather than breaking this one. Child loggers (withTag, withScope, withDefaults, create) are covered too. A reporter that throws is reported on the console instead of breaking the log call, and a logger created with the reporter in its own reporters keeps it after unsubscribing.
Installation
Add the package to your package.json dependencies. After changing dependencies, run npm run bootstrap (or your project's equivalent). See package.json basics for more information.
{
"dependencies": {
"@genesislcap/foundation-logger": "latest"
}
}License
Note: this project provides front-end dependencies and uses licensed components listed in the next section; thus, licenses for those components are required during development. Contact Genesis Global for more details.
Licensed components
Genesis low-code platform
