mirror of
https://github.com/rxliuli/apps.apple.com.git
synced 2025-11-10 01:10:34 +00:00
init commit
This commit is contained in:
31
shared/logger/src/index.ts
Normal file
31
shared/logger/src/index.ts
Normal file
@@ -0,0 +1,31 @@
|
||||
import { getContext } from 'svelte';
|
||||
import type { Logger, LoggerFactory } from './types';
|
||||
|
||||
export * from './composite';
|
||||
export * from './console';
|
||||
export * from './deferred';
|
||||
export * from './recording';
|
||||
export * from './sampled';
|
||||
export * from './types';
|
||||
export * from './void';
|
||||
|
||||
const CONTEXT_NAME = 'loggerFactory';
|
||||
|
||||
export function setContext(
|
||||
context: Map<string, unknown>,
|
||||
factory: LoggerFactory,
|
||||
): void {
|
||||
context.set(CONTEXT_NAME, factory);
|
||||
}
|
||||
|
||||
export function loggerFor(subject: string): Logger {
|
||||
const factory = getContext(CONTEXT_NAME) as LoggerFactory | undefined;
|
||||
|
||||
if (!factory) {
|
||||
throw new Error(
|
||||
'loggerFor called before setContext or outside of svelte component init',
|
||||
);
|
||||
}
|
||||
|
||||
return factory.loggerFor(subject);
|
||||
}
|
||||
Reference in New Issue
Block a user