Unify Logger interface usage

Summary:
Unified all imports of Logger. Some were called LogManager before.
Now the fb-stub and the fb variants use the same interface.
Constructor of Logger is no longer exposed so it can't be initialized twice, unless in the case you're explicitly using the fb variant, which has extra functionality.

Reviewed By: danielbuechele

Differential Revision: D14083929

fbshipit-source-id: 9b61a06e1264d5f142b5a9188465c99deaf18193
This commit is contained in:
John Knox
2019-02-14 09:10:58 -08:00
committed by Facebook Github Bot
parent 8ff4c4f56d
commit e33e2d4d06
24 changed files with 56 additions and 34 deletions

View File

@@ -5,12 +5,12 @@
* @format
*/
import type LogManager from './Logger';
import type {Logger} from '../fb-interfaces/Logger';
import type {Store} from '../reducers/index.js';
export default class BugReporter {
constructor(logManager: LogManager, store: Store) {}
constructor(logManager: Logger, store: Store) {}
async report(title: string, body: string): Promise<number> {
return Promise.resolve(-1);
}

View File

@@ -7,7 +7,7 @@
/*
* This class exists to allow error reporting to your own service.
* The recommended way to use this, is to instantiate it inside LogManager,
* The recommended way to use this, is to instantiate it inside Logger,
* so that all logged errors get reported to this class.
*/
export function cleanStack(stack: string, loc: ?string) {}

View File

@@ -5,18 +5,17 @@
* @format
*/
export type LogTypes = 'error' | 'warn' | 'info' | 'debug';
export type TrackType = 'duration' | 'usage' | 'performance' | 'success-rate';
import type {TrackType, Logger} from '../fb-interfaces/Logger';
import type {Store} from '../reducers/index';
import ScribeLogger from './ScribeLogger';
var instance: ?LogManager = null;
var instance: ?StubLogger = null;
type Args = {
isHeadless?: boolean,
};
export default class LogManager {
class StubLogger implements Logger {
constructor(store: Store, args?: Args) {
this.scribeLogger = new ScribeLogger(this);
}
@@ -36,15 +35,15 @@ export default class LogManager {
debug(data: any, category: string) {}
}
export function init(store: Store, args?: Args): LogManager {
export function init(store: Store, args?: Args): Logger {
if (instance) {
throw new Error('Attempted to initialize Logger when already initialized');
}
instance = new LogManager(store);
instance = new StubLogger(store);
return instance;
}
export function getInstance(): LogManager {
export function getInstance(): Logger {
if (!instance) {
throw new Error(
'Requested Logger instance without initializing it. Make sure init() is called at app start',

View File

@@ -10,7 +10,7 @@ export type ScribeMessage = {|
message: string,
|};
import type Logger from './Logger.js';
import type {Logger} from '../fb-interfaces/Logger.js';
export default class ScribeLogger {
constructor(logger: Logger) {}