All logs to be emitted

Summary: Error logs were missing, they're now reported.

Reviewed By: antonk52

Differential Revision: D47944591

fbshipit-source-id: a1f5515dded7c2e8955522e12554cd5f520d4c88
This commit is contained in:
Lorenzo Blasa
2023-08-01 03:45:05 -07:00
committed by Facebook GitHub Bot
parent 7e9228985b
commit 830ac6eac9

View File

@@ -29,11 +29,18 @@ type ConnectionRecorderEvents = {
};
class Recorder {
private flipperServer: FlipperServerImpl | undefined;
private flipperServer_: FlipperServerImpl | undefined;
private undefinedClientQuery_: ClientQuery = {
app: 'NONE',
device: 'NONE',
medium: 'NONE',
os: 'Browser',
device_id: '',
};
private handler_ = {
cmd: (payload: CommandEventPayload) => {
if (this.flipperServer) {
if (this.flipperServer_) {
const clientQuery = payload.context as ClientQuery | undefined;
const device = clientQuery?.device ?? 'NONE';
@@ -55,11 +62,31 @@ class Recorder {
troubleshoot: payload.troubleshoot,
};
this.flipperServer.emit('connectivity-troubleshoot-cmd', entry);
this.flipperServer_.emit('connectivity-troubleshoot-cmd', entry);
}
},
};
private log_ = (
type: 'info' | 'warning' | 'error',
clientQuery: ClientQuery,
...args: any[]
) => {
console.log(`[conn][${type}]`, ...args);
if (this.flipperServer_) {
const entry: ConnectionRecordEntry = {
time: new Date(),
type,
device: clientQuery.device,
app: clientQuery.app,
message: args.join(' '),
medium: clientQuery.medium,
};
this.flipperServer_.emit('connectivity-troubleshoot-log', entry);
}
};
event<Event extends keyof ConnectionRecorderEvents>(
event: Event,
payload: ConnectionRecorderEvents[Event],
@@ -72,29 +99,19 @@ class Recorder {
}
log(clientQuery: ClientQuery, ...args: any[]) {
console.log('[conn]', ...args);
if (this.flipperServer) {
const entry: ConnectionRecordEntry = {
time: new Date(),
type: 'info',
device: clientQuery.device,
app: clientQuery.app,
message: args.join(' '),
medium: clientQuery.medium,
};
this.log_('info', clientQuery, args);
}
this.flipperServer.emit('connectivity-troubleshoot-log', entry);
}
}
rawError(...args: any[]) {
console.error('[conn]', ...args);
this.log_('error', this.undefinedClientQuery_, args);
}
error(clientQuery: ClientQuery, ...args: any[]) {
console.error('[conn]', ...args);
this.log_('error', clientQuery, args);
}
enable(flipperServer: FlipperServerImpl) {
this.flipperServer = flipperServer;
this.flipperServer_ = flipperServer;
}
}