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

@@ -22,7 +22,7 @@ import {
ACTIVE_SHEET_PLUGIN_DEBUGGER,
} from './reducers/application.js';
import type Logger from './fb-stubs/Logger.js';
import type {Logger} from './fb-interfaces/Logger.js';
import type BugReporter from './fb-stubs/BugReporter.js';
import type BaseDevice from './devices/BaseDevice.js';
import type {ActiveSheet} from './reducers/application.js';

View File

@@ -8,7 +8,7 @@
import type {FlipperPlugin, FlipperBasePlugin} from './plugin.js';
import type BaseDevice from './devices/BaseDevice.js';
import type {App} from './App.js';
import type Logger from './fb-stubs/Logger.js';
import type {Logger} from './fb-interfaces/Logger.js';
import type {Store} from './reducers/index.js';
import type {OS} from './devices/BaseDevice.js';
import {FlipperDevicePlugin} from './plugin.js';

View File

@@ -12,7 +12,7 @@ import type {
Device,
} from 'flipper';
import type {PluginNotification} from './reducers/notifications';
import type Logger from './fb-stubs/Logger';
import type {Logger} from './fb-interfaces/Logger';
import {
FlipperDevicePlugin,

View File

@@ -5,7 +5,7 @@
* @format
*/
import type {FlipperPlugin, FlipperDevicePlugin} from './plugin.js';
import type LogManager from './fb-stubs/Logger';
import type {Logger} from './fb-interfaces/Logger';
import BaseDevice from './devices/BaseDevice.js';
import type {Props as PluginProps} from './plugin';
@@ -46,7 +46,7 @@ deepLinkPayload,
pluginKey,
*/
type OwnProps = {|
logger: LogManager,
logger: Logger,
|};
type Props = {|

View File

@@ -15,13 +15,13 @@ import path from 'path';
import {remote} from 'electron';
import {FlipperPlugin} from '../../plugin';
import reducers from '../../reducers/index.js';
import Logger from '../../fb-stubs/Logger.js';
import {init as initLogger} from '../../fb-stubs/Logger.js';
import configureStore from 'redux-mock-store';
import {TEST_PASSING_GK, TEST_FAILING_GK} from '../../fb-stubs/GK';
import TestPlugin from './TestPlugin';
const mockStore = configureStore([])(reducers(undefined, {type: 'INIT'}));
const logger = new Logger(mockStore);
const logger = initLogger(mockStore);
test('dispatcher dispatches REGISTER_PLUGINS', () => {
dispatcher(mockStore, logger);

View File

@@ -11,7 +11,7 @@ import promiseRetry from 'promise-retry';
import {promisify} from 'util';
import type {Store} from '../reducers/index.js';
import type BaseDevice from '../devices/BaseDevice';
import type Logger from '../fb-stubs/Logger.js';
import type {Logger} from '../fb-interfaces/Logger.js';
import {registerDeviceCallbackOnPlugins} from '../utils/onRegisterDevice.js';
import {reportPlatformFailures} from '../utils/metrics';
import adbConfig from '../utils/adbConfig';

View File

@@ -7,7 +7,7 @@
import {remote, ipcRenderer} from 'electron';
import type {Store} from '../reducers/index.js';
import type Logger from '../fb-stubs/Logger.js';
import type {Logger} from '../fb-interfaces/Logger.js';
import {parseFlipperPorts} from '../utils/environmentVariables';
import {importFileToStore} from '../utils/exportData';
import {selectPlugin, userPreferredPlugin} from '../reducers/connections';

View File

@@ -7,7 +7,7 @@
import type {ChildProcess} from 'child_process';
import type {Store} from '../reducers/index.js';
import type Logger from '../fb-stubs/Logger.js';
import type {Logger} from '../fb-interfaces/Logger.js';
import type {DeviceType} from '../devices/BaseDevice';
import {RecurringError} from '../utils/errors';
import {promisify} from 'util';

View File

@@ -14,7 +14,7 @@ import server from './server';
import notifications from './notifications';
import plugins from './plugins';
import type Logger from '../fb-stubs/Logger.js';
import type {Logger} from '../fb-interfaces/Logger.js';
import type {Store} from '../reducers/index.js';
export default (store: Store, logger: Logger) =>

View File

@@ -6,7 +6,7 @@
*/
import type {Store} from '../reducers/index.js';
import type Logger from '../fb-stubs/Logger.js';
import type {Logger} from '../fb-interfaces/Logger.js';
import type {PluginNotification} from '../reducers/notifications';
import type {FlipperPlugin, FlipperDevicePlugin} from '../plugin.js';

View File

@@ -6,7 +6,7 @@
*/
import type {Store} from '../reducers/index.js';
import type Logger from '../fb-stubs/Logger.js';
import type {Logger} from '../fb-interfaces/Logger.js';
import type {FlipperPlugin, FlipperDevicePlugin} from '../plugin.js';
import type {State} from '../reducers/plugins';

View File

@@ -8,7 +8,7 @@
import Server from '../server.js';
import type {Store} from '../reducers/index.js';
import type Logger from '../fb-stubs/Logger.js';
import type {Logger} from '../fb-interfaces/Logger.js';
import type Client from '../Client.js';
import type {UninitializedClient} from '../UninitializedClient';

View File

@@ -10,7 +10,7 @@ import {ipcRenderer} from 'electron';
import {performance} from 'perf_hooks';
import type {Store} from '../reducers/index.js';
import type Logger from '../fb-stubs/Logger.js';
import type {Logger} from '../fb-interfaces/Logger.js';
export default (store: Store, logger: Logger) => {
let droppedFrames: number = 0;

View File

@@ -6,7 +6,7 @@
*/
import type {Store} from '../reducers/index.js';
import type Logger from '../fb-stubs/Logger.js';
import type {Logger} from '../fb-interfaces/Logger.js';
import WindowsDevice from '../devices/WindowsDevice';

View File

@@ -0,0 +1,23 @@
/**
* 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
*/
export type LogTypes = 'error' | 'warn' | 'info' | 'debug';
export type TrackType = 'duration' | 'usage' | 'performance' | 'success-rate';
export interface Logger {
track(type: TrackType, event: string, data: ?any, plugin?: string): void;
trackTimeSince(mark: string, eventName: ?string): void;
info(data: any, category: string): void;
warn(data: any, category: string): void;
error(data: any, category: string): void;
debug(data: any, category: string): void;
}

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) {}

View File

@@ -7,7 +7,7 @@
import type {KeyboardActions} from './MenuBar.js';
import type {App} from './App.js';
import type Logger from './fb-stubs/Logger.js';
import type {Logger} from './fb-interfaces/Logger.js';
import type Client from './Client.js';
import type {Store} from './reducers/index.js';

View File

@@ -30,7 +30,7 @@ import {
// $FlowFixMe perf_hooks is a new API in node
import {performance} from 'perf_hooks';
import type {TrackType} from '../../fb-stubs/Logger.js';
import type {TrackType} from '../../fb-interfaces/Logger.js';
import debounce from 'lodash.debounce';

View File

@@ -6,7 +6,7 @@
*/
import type {SecureServerConfig} from './utils/CertificateProvider';
import type Logger from './fb-stubs/Logger';
import type {Logger} from './fb-interfaces/Logger';
import type {ClientQuery} from './Client.js';
import type {Store} from './reducers/index.js';

View File

@@ -8,7 +8,7 @@
import type {Element} from './ElementsInspector.js';
import type {PluginClient} from '../../../plugin';
import type Client from '../../../Client.js';
import type Logger from '../../../fb-stubs/Logger.js';
import type {Logger} from '../../../fb-interfaces/Logger.js';
import Panel from '../Panel.js';
import ManagedDataInspector from '../data-inspector/ManagedDataInspector.js';
import {Component} from 'react';

View File

@@ -5,7 +5,7 @@
* @format
*/
import LogManager from '../fb-stubs/Logger';
import type {Logger} from '../fb-interfaces/Logger';
import {RecurringError} from './errors';
import {promisify} from 'util';
const fs = require('fs');
@@ -70,12 +70,12 @@ export type SecureServerConfig = {|
* Flipper CA.
*/
export default class CertificateProvider {
logger: LogManager;
logger: Logger;
adb: any;
certificateSetup: Promise<void>;
server: Server;
constructor(server: Server, logger: LogManager) {
constructor(server: Server, logger: Logger) {
this.logger = logger;
this.adb = adb.createClient(adbConfig());
this.certificateSetup = reportPlatformFailures(