UNPKG

1.07 kBPlain TextView Raw
1import { createLogger } from './factories/createLogger';
2import { createRoarrInitialGlobalState } from './factories/createRoarrInitialGlobalState';
3import { type MessageSerializer, type RoarrGlobalState } from './types';
4import { stringify } from './utilities/stringify';
5
6const ROARR = createRoarrInitialGlobalState(
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 LogWriter,
28 Message,
29 MessageContext,
30 MessageEventHandler,
31 MessageSerializer,
32 RoarrGlobalState,
33 TransformMessageFunction,
34} from './types';
35
36export { ROARR, Roarr };
37
38export { logLevels } from './constants';
39export { getLogLevelName } from './getLogLevelName';