Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
import createGlobalThis from 'globalthis';
import stringify from 'json-stringify-safe';
import {
sprintf,
} from 'sprintf-js';
import type {
LoggerType,
MessageContextType,
MessageEventHandlerType,
TranslateMessageFunctionType,
} from '../types';
import {
logLevels,
} from '../constants';
const globalThis = createGlobalThis();
const createLogger = (onMessage: MessageEventHandlerType, parentContext?: MessageContextType): LoggerType => {
// eslint-disable-next-line id-length, unicorn/prevent-abbreviations
const log = (a, b, c, d, e, f, g, h, i, k) => {
const time = Date.now();
const sequence = globalThis.ROARR.sequence++;
let context;
let message;
if (typeof a === 'string') {
context = {
...parentContext || {},
};
message = sprintf(a, b, c, d, e, f, g, h, i, k);
} else {
// @flow
import {
boolean,
} from 'boolean';
import createGlobalThis from 'globalthis';
import environmentIsNode from 'detect-node';
import {
createLogger,
createMockLogger,
createRoarrInititialGlobalState,
} from './factories';
const globalThis = createGlobalThis();
globalThis.ROARR = createRoarrInititialGlobalState(globalThis.ROARR || {});
let logFactory = createLogger;
if (environmentIsNode) {
// eslint-disable-next-line no-process-env
const enabled = boolean(process.env.ROARR_LOG || '');
if (!enabled) {
logFactory = createMockLogger;
}
}
export type {
LoggerType,
beforeEach(() => {
const globalThis = createGlobalThis();
globalThis.ROARR = createRoarrInititialGlobalState({});
});