Files
flipper/src/fb-stubs/Logger.tsx
Pascal Hartig a60bcf7aca Make fb-stubs/Logger.tsx strict
Summary: _typescript_

Reviewed By: jknoxville

Differential Revision: D17204281

fbshipit-source-id: c694aed012c30cc325fe507723476a3e6bc43e83
2019-09-09 07:04:53 -07:00

54 lines
1.3 KiB
TypeScript

/**
* Copyright 2018-present Facebook.
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
* @format
*/
import {TrackType, Logger} from '../fb-interfaces/Logger';
import {Store} from '../reducers/index';
import ScribeLogger from './ScribeLogger';
let instance: StubLogger | null = null;
type Args = {
isHeadless?: boolean;
};
class StubLogger implements Logger {
constructor(store: Store, args?: Args) {
this.scribeLogger = new ScribeLogger(this);
}
scribeLogger: ScribeLogger;
track(type: TrackType, event: string, data?: any, plugin?: string) {}
trackTimeSince(mark: string, eventName?: string) {}
info(data: any, category: string) {}
warn(data: any, category: string) {}
error(data: any, category: string) {}
debug(data: any, category: string) {}
}
export function init(store: Store, args?: Args): Logger {
if (instance) {
throw new Error('Attempted to initialize Logger when already initialized');
}
instance = new StubLogger(store);
return instance;
}
export function getInstance(): Logger {
if (!instance) {
throw new Error(
'Requested Logger instance without initializing it. Make sure init() is called at app start',
);
}
return instance;
}