Skip to content

Commit

Permalink
perf(logger): flexible use [skip release]
Browse files Browse the repository at this point in the history
  • Loading branch information
pablo1v committed Feb 13, 2021
1 parent 9be2c2b commit b0ec486
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 16 deletions.
4 changes: 2 additions & 2 deletions __tests__/setup.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import '@testing-library/jest-dom';
import '@/polyfills/index';

import { disableLogger } from '@/constants/logger';
import { logger } from '@/shared/logger';

disableLogger();
logger.disable();
5 changes: 0 additions & 5 deletions src/constants/logger.ts

This file was deleted.

2 changes: 1 addition & 1 deletion src/hooks/useOutClick.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { useRef, useEffect, useCallback, RefObject } from 'react';

import { logger } from '@/shared/logger';
import { hasNodeInDOM } from '@/utilities/hasNodeInDOM';
import { logger } from '@/utilities/internal/logger';
import { isElement } from '@/utilities/isElement';

import type { Listener } from '@/shared/types';
Expand Down
5 changes: 2 additions & 3 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
import './polyfills/index.js';

// Logger
export * from './constants/logger';
// Shared

// Types
export * from './shared/types';
export * from './shared/logger';

// Hooks

Expand Down
19 changes: 14 additions & 5 deletions src/utilities/internal/logger.ts → src/shared/logger.ts
Original file line number Diff line number Diff line change
@@ -1,20 +1,29 @@
/* eslint-disable no-console */

import { LOGGER_DISABLED } from '@/constants/logger';

import { isUndefinedOrNull } from './isUndefinedOrNull';
import { isUndefinedOrNull } from '@/utilities/internal/isUndefinedOrNull';

type LogMethod = (message: string) => void;

type LogCallback = (message: string, stackTrace: string) => void;

let LOGGER_DISABLED = false;

export const logger = {
/* eslint-disable no-console */

info: middleware(message => {
console.log(message);
}),
warn: middleware(message => {
console.warn(message);
}),
error: middleware((message, stackTrace) => {
console.error(`Error: ${message}\n${stackTrace}`);
}),

/* eslint-enable no-console */

disable(): void {
LOGGER_DISABLED = true;
},
};

/**
Expand Down

0 comments on commit b0ec486

Please sign in to comment.