Skip to content

Commit

Permalink
move types to loggerFactory
Browse files Browse the repository at this point in the history
issue with `rollup-plugin-typescript2` (developit/microbundle#669 (comment))
  • Loading branch information
Matej Bransky committed Jan 2, 2021
1 parent a2045fb commit d126963
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 45 deletions.
3 changes: 1 addition & 2 deletions packages/logger/src/loggerFactory.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { Log } from './types';
import { LogLevel, LogMethod } from './constants';
import loggerFactory, { defaultPrefixer } from './loggerFactory';
import loggerFactory, { defaultPrefixer, Log } from './loggerFactory';

describe('logger', () => {
let consoleSpy = {} as Record<LogMethod, jest.SpyInstance>;
Expand Down
42 changes: 34 additions & 8 deletions packages/logger/src/loggerFactory.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,4 @@
import { DEFAULT_LEVEL, LogLevel, LogMethod } from './constants';
import {
Log,
Logger,
LoggerCache,
LoggerFactory,
Prefixer,
Subscriber,
} from './types';

export const defaultPrefixer: Prefixer = (logMeta) =>
`[${logMeta.loggerName}][${logMeta.logLevel}]`;
Expand Down Expand Up @@ -113,3 +105,37 @@ export default (function loggerFactory(): LoggerFactory {
return proxifiedLogger as Logger;
}
})();

export interface LoggerFactory {
getDefaultLevel: () => LogLevel;
setDefaultLevel: (level: keyof typeof LogLevel) => void;
getLogger: (name: string) => Logger;
getLoggerCache: () => LoggerCache;
setPrefix: (prefixer: Prefixer) => void;
subscribe: (subscriber: Subscriber) => Unsubscribe;
}

export type Subscriber = (log: Log) => void;
type Unsubscribe = () => void;

export type Prefixer = (meta: LogMeta) => string;

export type LoggerCache = Record<string, { level?: LogLevel; logger: Logger }>;

export type Logger = Console & {
setLevel: (level: keyof typeof LogLevel) => void;
getLevel: () => LogLevel;
};

export type LogMeta = {
loggerName: string;
logLevel: LogMethod;
};

export type Log = LogMeta & {
stackTrace?: string;
date: Date;
args: any[];
};

export type Formatter = (logMeta: LogMeta) => unknown;
35 changes: 0 additions & 35 deletions packages/logger/src/types.ts

This file was deleted.

0 comments on commit d126963

Please sign in to comment.