UNPKG

1.08 kBPlain TextView Raw
1import { createLogger } from './factories/createLogger';
2import { createRoarrInitialGlobalStateBrowser } from './factories/createRoarrInitialGlobalStateBrowser';
3import { type MessageSerializer, type RoarrGlobalState } from './types';
4import { stringify } from './utilities/stringify';
5
6const ROARR = createRoarrInitialGlobalStateBrowser(
7 (globalThis.ROARR as RoarrGlobalState) || {},
8);
9
10globalThis.ROARR = ROARR;
11
12const serializeMessage: MessageSerializer = (message) => {
13 return stringify(message);
14};
15
16const Roarr = createLogger((message) => {
17 if (ROARR.write) {
18 // Stringify message as soon as it is received to prevent
19 // properties of the context from being modified by reference.
20 ROARR.write((ROARR.serializeMessage ?? serializeMessage)(message));
21 }
22});
23
24export type {
25 Logger,
26 LogLevelName,
27 Message,
28 MessageContext,
29 MessageEventHandler,
30 MessageSerializer,
31 RoarrGlobalState,
32 TransformMessageFunction,
33} from './types';
34
35export { ROARR, Roarr };
36
37export { logLevels } from './constants';
38export { getLogLevelName } from './getLogLevelName';