Centralise logging

Summary:
Centralise connectivity logging into a single place. By having all logs go through a single interface, then it becomes trivial to manipulate them as needed.

In this change, this is not done.

In subsequent diffs, logs will be dispatched via an event and will be visualised in the Connectivity Hub.

Reviewed By: passy

Differential Revision: D47185054

fbshipit-source-id: fb5eab98895be0c8f61fb9a77d3e66d6a8dbcb27
This commit is contained in:
Lorenzo Blasa
2023-07-10 04:14:14 -07:00
committed by Facebook GitHub Bot
parent 49d1a8b0fa
commit fc38355eee
22 changed files with 351 additions and 258 deletions

View File

@@ -0,0 +1,62 @@
/**
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @format
*/
import {getLogger, CertificateExchangeMedium} from 'flipper-common';
type AppConnectionPayload = {
app: string;
os: string;
device: string;
device_id: string;
medium?: CertificateExchangeMedium;
};
type AppConnectionCertificateExchangePayload = AppConnectionPayload & {
successful: boolean;
error?: string;
};
type ServerBootstrapPerformancePayload = {
loggerInitializedMS: number;
keytarLoadedMS: number;
runningInstanceShutdownMS: number;
httpServerStartedMS: number;
serverCreatedMS: number;
companionEnvironmentInitializedMS: number;
appServerStartedMS: number;
developmentServerAttachedMS: number;
serverStartedMS: number;
};
type TrackerEvents = {
'server-bootstrap-performance': ServerBootstrapPerformancePayload;
'server-started': {port: number; tcp: boolean};
'server-auth-token-verification': {
successful: boolean;
present: boolean;
error?: string;
};
'server-socket-already-in-use': {};
'server-proxy-error': {error: string};
'app-connection-created': AppConnectionPayload;
'app-connection-secure-attempt': AppConnectionPayload;
'app-connection-insecure-attempt': AppConnectionPayload;
'app-connection-certificate-exchange': AppConnectionCertificateExchangePayload;
};
class ServerCoreTracker {
track<Event extends keyof TrackerEvents>(
event: Event,
payload: TrackerEvents[Event],
): void {
getLogger().track('usage', event, payload);
}
}
export const tracker = new ServerCoreTracker();