Stash and export debug logs
Summary: Design doc: https://docs.google.com/document/d/1HLCFl46RfqG0o1mSt8SWrwf_HMfOCRg_oENioc1rkvQ/edit# Stash all logs including debug ones for the export Reviewed By: lblasa Differential Revision: D40467905 fbshipit-source-id: 963ce8e92d2131220640a63f5e9c38f4317af061
This commit is contained in:
committed by
Facebook GitHub Bot
parent
be72375d18
commit
0e5af8095f
@@ -19,22 +19,28 @@ import {useIsDarkMode} from '../utils/useIsDarkMode';
|
|||||||
import {Button, Dropdown, Menu, Checkbox} from 'antd';
|
import {Button, Dropdown, Menu, Checkbox} from 'antd';
|
||||||
import {DownOutlined} from '@ant-design/icons';
|
import {DownOutlined} from '@ant-design/icons';
|
||||||
import {DeleteOutlined} from '@ant-design/icons';
|
import {DeleteOutlined} from '@ant-design/icons';
|
||||||
|
import CBuffer from 'cbuffer';
|
||||||
|
|
||||||
const MAX_LOG_ITEMS = 1000;
|
const MAX_DISPLAY_LOG_ITEMS = 1000;
|
||||||
|
const MAX_EXPORT_LOG_ITEMS = 5000;
|
||||||
|
|
||||||
export const logsAtom = createState<any[]>([]);
|
// A list5 of log items meant to be used for exporting (and subsequent debugging) only
|
||||||
|
export const exportLogs = new CBuffer<any>(MAX_EXPORT_LOG_ITEMS);
|
||||||
|
export const displayLogsAtom = createState<any[]>([]);
|
||||||
export const errorCounterAtom = createState(0);
|
export const errorCounterAtom = createState(0);
|
||||||
|
|
||||||
export function enableConsoleHook() {
|
export function enableConsoleHook() {
|
||||||
Hook(
|
Hook(
|
||||||
window.console,
|
window.console,
|
||||||
(log) => {
|
(log) => {
|
||||||
|
exportLogs.push(log);
|
||||||
|
|
||||||
if (log.method === 'debug') {
|
if (log.method === 'debug') {
|
||||||
return; // See below, skip debug messages which are generated very aggressively by Flipper
|
return; // See below, skip debug messages which are generated very aggressively by Flipper
|
||||||
}
|
}
|
||||||
const newLogs = logsAtom.get().slice(-MAX_LOG_ITEMS);
|
const newLogs = displayLogsAtom.get().slice(-MAX_DISPLAY_LOG_ITEMS);
|
||||||
newLogs.push(log);
|
newLogs.push(log);
|
||||||
logsAtom.set(newLogs);
|
displayLogsAtom.set(newLogs);
|
||||||
if (log.method === 'error' || log.method === 'assert') {
|
if (log.method === 'error' || log.method === 'assert') {
|
||||||
errorCounterAtom.set(errorCounterAtom.get() + 1);
|
errorCounterAtom.set(errorCounterAtom.get() + 1);
|
||||||
}
|
}
|
||||||
@@ -44,7 +50,8 @@ export function enableConsoleHook() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function clearLogs() {
|
function clearLogs() {
|
||||||
logsAtom.set([]);
|
exportLogs.empty();
|
||||||
|
displayLogsAtom.set([]);
|
||||||
errorCounterAtom.set(0);
|
errorCounterAtom.set(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -67,7 +74,7 @@ const defaultLogLevels: Methods[] = ['warn', 'error', 'table', 'assert'];
|
|||||||
|
|
||||||
export function ConsoleLogs() {
|
export function ConsoleLogs() {
|
||||||
const isDarkMode = useIsDarkMode();
|
const isDarkMode = useIsDarkMode();
|
||||||
const logs = useValue(logsAtom);
|
const logs = useValue(displayLogsAtom);
|
||||||
const [logLevels, setLogLevels] = useLocalStorageState<Methods[]>(
|
const [logLevels, setLogLevels] = useLocalStorageState<Methods[]>(
|
||||||
'console-logs-loglevels',
|
'console-logs-loglevels',
|
||||||
defaultLogLevels,
|
defaultLogLevels,
|
||||||
|
|||||||
@@ -32,7 +32,7 @@ import ShareSheetExportFile from '../chrome/ShareSheetExportFile';
|
|||||||
import ExportDataPluginSheet from '../chrome/ExportDataPluginSheet';
|
import ExportDataPluginSheet from '../chrome/ExportDataPluginSheet';
|
||||||
import {getRenderHostInstance} from 'flipper-frontend-core';
|
import {getRenderHostInstance} from 'flipper-frontend-core';
|
||||||
import {uploadFlipperMedia} from '../fb-stubs/user';
|
import {uploadFlipperMedia} from '../fb-stubs/user';
|
||||||
import {logsAtom} from '../chrome/ConsoleLogs';
|
import {exportLogs} from '../chrome/ConsoleLogs';
|
||||||
|
|
||||||
export const IMPORT_FLIPPER_TRACE_EVENT = 'import-flipper-trace';
|
export const IMPORT_FLIPPER_TRACE_EVENT = 'import-flipper-trace';
|
||||||
export const EXPORT_FLIPPER_TRACE_EVENT = 'export-flipper-trace';
|
export const EXPORT_FLIPPER_TRACE_EVENT = 'export-flipper-trace';
|
||||||
@@ -606,8 +606,7 @@ export function canFileExport() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export async function startLogsExport() {
|
export async function startLogsExport() {
|
||||||
const serializedLogs = logsAtom
|
const serializedLogs = exportLogs
|
||||||
.get()
|
|
||||||
.map((item) => JSON.stringify(item))
|
.map((item) => JSON.stringify(item))
|
||||||
.join('\n');
|
.join('\n');
|
||||||
await getRenderHostInstance().exportFile?.(serializedLogs);
|
await getRenderHostInstance().exportFile?.(serializedLogs);
|
||||||
|
|||||||
Reference in New Issue
Block a user