Add log tailing infra and downgrade resize observer error to warn
Summary: Resize oberserver limit exceeded appears to be a benign error that we can safely ignore, added ability to change log level. Given we report errors to our user logs, fb log view and console the console log patching has been centralised and now logs are pushed to whatever destinations we have. Reviewed By: lblasa Differential Revision: D44666836 fbshipit-source-id: e028dbc52b00947097833f9f3619189226247e1d
This commit is contained in:
committed by
Facebook GitHub Bot
parent
8f5fcf9444
commit
a9b17ac637
@@ -9,7 +9,7 @@
|
||||
|
||||
import {useMemo} from 'react';
|
||||
import React from 'react';
|
||||
import {Console, Hook} from 'console-feed';
|
||||
import {Console} from 'console-feed';
|
||||
import type {Methods} from 'console-feed/lib/definitions/Methods';
|
||||
import type {Styles} from 'console-feed/lib/definitions/Styles';
|
||||
import {createState, useValue} from 'flipper-plugin';
|
||||
@@ -20,33 +20,40 @@ import {Button, Dropdown, Menu, Checkbox} from 'antd';
|
||||
import {DownOutlined} from '@ant-design/icons';
|
||||
import {DeleteOutlined} from '@ant-design/icons';
|
||||
import CBuffer from 'cbuffer';
|
||||
import {addLogTailer} from '../consoleLogTailer';
|
||||
import {v4} from 'uuid';
|
||||
|
||||
const MAX_DISPLAY_LOG_ITEMS = 1000;
|
||||
const MAX_EXPORT_LOG_ITEMS = 5000;
|
||||
|
||||
// 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 exportLogs = new CBuffer<ConsoleFeedLogMessage>(
|
||||
MAX_EXPORT_LOG_ITEMS,
|
||||
);
|
||||
export const displayLogsAtom = createState<ConsoleFeedLogMessage[]>([]);
|
||||
export const errorCounterAtom = createState(0);
|
||||
|
||||
export function enableConsoleHook() {
|
||||
Hook(
|
||||
window.console,
|
||||
(log) => {
|
||||
exportLogs.push(log);
|
||||
type ConsoleFeedLogMessage = {
|
||||
id: string;
|
||||
method: Methods;
|
||||
data: any[];
|
||||
};
|
||||
|
||||
if (log.method === 'debug') {
|
||||
return; // See below, skip debug messages which are generated very aggressively by Flipper
|
||||
}
|
||||
const newLogs = displayLogsAtom.get().slice(-MAX_DISPLAY_LOG_ITEMS);
|
||||
newLogs.push(log);
|
||||
displayLogsAtom.set(newLogs);
|
||||
if (log.method === 'error' || log.method === 'assert') {
|
||||
errorCounterAtom.set(errorCounterAtom.get() + 1);
|
||||
}
|
||||
},
|
||||
false,
|
||||
);
|
||||
export function enableConsoleHook() {
|
||||
addLogTailer((level, ...data) => {
|
||||
const logMessage = {method: level, data: data, id: v4()};
|
||||
exportLogs.push(logMessage);
|
||||
|
||||
if (level === 'debug') {
|
||||
return; // See below, skip debug messages which are generated very aggressively by Flipper
|
||||
}
|
||||
const newLogs = displayLogsAtom.get().slice(-MAX_DISPLAY_LOG_ITEMS);
|
||||
newLogs.push(logMessage);
|
||||
displayLogsAtom.set(newLogs);
|
||||
if (level === 'error') {
|
||||
errorCounterAtom.set(errorCounterAtom.get() + 1);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
function clearLogs() {
|
||||
|
||||
Reference in New Issue
Block a user