diff --git a/src/App.js b/src/App.js index 376c821c9..c30e127a9 100644 --- a/src/App.js +++ b/src/App.js @@ -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'; diff --git a/src/Client.js b/src/Client.js index 8a6808769..a1a43d7bc 100644 --- a/src/Client.js +++ b/src/Client.js @@ -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'; diff --git a/src/NotificationsHub.js b/src/NotificationsHub.js index c09ff8994..eebaa499f 100644 --- a/src/NotificationsHub.js +++ b/src/NotificationsHub.js @@ -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, diff --git a/src/PluginContainer.js b/src/PluginContainer.js index 2894cb96f..241c1d55c 100644 --- a/src/PluginContainer.js +++ b/src/PluginContainer.js @@ -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 = {| diff --git a/src/dispatcher/__tests__/plugins.electron.js b/src/dispatcher/__tests__/plugins.electron.js index 82d30cc5e..170d8f6c2 100644 --- a/src/dispatcher/__tests__/plugins.electron.js +++ b/src/dispatcher/__tests__/plugins.electron.js @@ -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); diff --git a/src/dispatcher/androidDevice.js b/src/dispatcher/androidDevice.js index f2b270aef..9cb3b5f3e 100644 --- a/src/dispatcher/androidDevice.js +++ b/src/dispatcher/androidDevice.js @@ -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'; diff --git a/src/dispatcher/application.js b/src/dispatcher/application.js index 74451c343..1ca86336c 100644 --- a/src/dispatcher/application.js +++ b/src/dispatcher/application.js @@ -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'; diff --git a/src/dispatcher/iOSDevice.js b/src/dispatcher/iOSDevice.js index 4a068886c..1c01654cb 100644 --- a/src/dispatcher/iOSDevice.js +++ b/src/dispatcher/iOSDevice.js @@ -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'; diff --git a/src/dispatcher/index.js b/src/dispatcher/index.js index 4bae83bf8..58ecbee3c 100644 --- a/src/dispatcher/index.js +++ b/src/dispatcher/index.js @@ -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) => diff --git a/src/dispatcher/notifications.js b/src/dispatcher/notifications.js index 8579fb15e..428f7b80b 100644 --- a/src/dispatcher/notifications.js +++ b/src/dispatcher/notifications.js @@ -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'; diff --git a/src/dispatcher/plugins.js b/src/dispatcher/plugins.js index b16b4bac5..84aadbe03 100644 --- a/src/dispatcher/plugins.js +++ b/src/dispatcher/plugins.js @@ -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'; diff --git a/src/dispatcher/server.js b/src/dispatcher/server.js index 32c0b0004..882c76ffb 100644 --- a/src/dispatcher/server.js +++ b/src/dispatcher/server.js @@ -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'; diff --git a/src/dispatcher/tracking.js b/src/dispatcher/tracking.js index 7c0ade564..75121569d 100644 --- a/src/dispatcher/tracking.js +++ b/src/dispatcher/tracking.js @@ -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; diff --git a/src/dispatcher/windowsDevice.js b/src/dispatcher/windowsDevice.js index e22098e99..01d2a293a 100644 --- a/src/dispatcher/windowsDevice.js +++ b/src/dispatcher/windowsDevice.js @@ -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'; diff --git a/src/fb-interfaces/Logger.js b/src/fb-interfaces/Logger.js new file mode 100644 index 000000000..e255bbd30 --- /dev/null +++ b/src/fb-interfaces/Logger.js @@ -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; +} diff --git a/src/fb-stubs/BugReporter.js b/src/fb-stubs/BugReporter.js index bd5ea8baa..d75ad8d27 100644 --- a/src/fb-stubs/BugReporter.js +++ b/src/fb-stubs/BugReporter.js @@ -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 { return Promise.resolve(-1); } diff --git a/src/fb-stubs/ErrorReporter.js b/src/fb-stubs/ErrorReporter.js index 2e075e4e2..37963857b 100644 --- a/src/fb-stubs/ErrorReporter.js +++ b/src/fb-stubs/ErrorReporter.js @@ -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) {} diff --git a/src/fb-stubs/Logger.js b/src/fb-stubs/Logger.js index 47ed449e9..11d2e575b 100644 --- a/src/fb-stubs/Logger.js +++ b/src/fb-stubs/Logger.js @@ -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', diff --git a/src/fb-stubs/ScribeLogger.js b/src/fb-stubs/ScribeLogger.js index 84b308388..335a01a82 100644 --- a/src/fb-stubs/ScribeLogger.js +++ b/src/fb-stubs/ScribeLogger.js @@ -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) {} diff --git a/src/plugin.js b/src/plugin.js index 77195c5fb..b19520264 100644 --- a/src/plugin.js +++ b/src/plugin.js @@ -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'; diff --git a/src/plugins/layout/index.js b/src/plugins/layout/index.js index 804d5c694..558734dde 100644 --- a/src/plugins/layout/index.js +++ b/src/plugins/layout/index.js @@ -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'; diff --git a/src/server.js b/src/server.js index 999cfd6a4..6ce1282d9 100644 --- a/src/server.js +++ b/src/server.js @@ -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'; diff --git a/src/ui/components/elements-inspector/sidebar.js b/src/ui/components/elements-inspector/sidebar.js index 7b4b57b50..894a12076 100644 --- a/src/ui/components/elements-inspector/sidebar.js +++ b/src/ui/components/elements-inspector/sidebar.js @@ -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'; diff --git a/src/utils/CertificateProvider.js b/src/utils/CertificateProvider.js index b5945b836..7584064cf 100644 --- a/src/utils/CertificateProvider.js +++ b/src/utils/CertificateProvider.js @@ -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; server: Server; - constructor(server: Server, logger: LogManager) { + constructor(server: Server, logger: Logger) { this.logger = logger; this.adb = adb.createClient(adbConfig()); this.certificateSetup = reportPlatformFailures(