Show additional data in debug log header

This commit is contained in:
Evan Hahn 2021-07-30 11:43:16 -05:00 committed by GitHub
parent 03874a788f
commit 689542a9b4
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
14 changed files with 278 additions and 89 deletions

View file

@ -2,10 +2,34 @@
// SPDX-License-Identifier: AGPL-3.0-only
import * as pino from 'pino';
import { isRecord } from '../util/isRecord';
import { redactAll } from '../util/privacy';
import { missingCaseError } from '../util/missingCaseError';
import { reallyJsonStringify } from '../util/reallyJsonStringify';
export type FetchLogIpcData = {
capabilities: Record<string, unknown>;
remoteConfig: Record<string, unknown>;
statistics: Record<string, unknown>;
user: Record<string, unknown>;
// We expect `logEntries` to be `Array<LogEntryType>`, but we don't validate that
// upfront—we only validate it when we go to log each line. This improves the
// performance, because we don't have to iterate over every single log entry twice. It
// also means we can log entries if only some of them are invalid.
logEntries: Array<unknown>;
};
// We don't use Zod here because it'd be slow parsing all of the log entries.
// Unfortunately, Zod is a bit slow even with `z.array(z.unknown())`.
export const isFetchLogIpcData = (data: unknown): data is FetchLogIpcData =>
isRecord(data) &&
isRecord(data.capabilities) &&
isRecord(data.remoteConfig) &&
isRecord(data.statistics) &&
isRecord(data.user) &&
Array.isArray(data.logEntries);
// These match [Pino's recommendations][0].
// [0]: https://getpino.io/#/docs/api?id=loggerlevels-object
export enum LogLevel {
@ -29,7 +53,7 @@ export type LogEntryType = Readonly<{
// whenever we want to send the debug log. We can't use `zod` because it clones
// the data on successful parse and ruins the performance.
export const isLogEntry = (data: unknown): data is LogEntryType => {
if (data === null || typeof data !== 'object') {
if (!isRecord(data)) {
return false;
}