Remove the previous misplaced log tailer

Summary: The log tailer is already defined in flipper-common, use that instead.

Reviewed By: passy

Differential Revision: D48524909

fbshipit-source-id: 1c0674276f08893ea80dc2fc9f8b45679f33e93e
This commit is contained in:
Lorenzo Blasa
2023-08-22 05:16:20 -07:00
committed by Facebook GitHub Bot
parent 64a4b3a899
commit b69358f6a2
5 changed files with 25 additions and 73 deletions

View File

@@ -20,6 +20,7 @@ export {
setLoggerInstance,
NoopLogger,
} from './utils/Logger';
export * from './utils/LoggerTailer';
export * from './server-types';
export * from './companion-types';
export * from './ServerAddOn';

View File

@@ -7,6 +7,7 @@
* @format
*/
import {getStringFromErrorLike} from './errors';
import {LoggerTypes} from './Logger';
export const logLevels: LoggerTypes[] = ['debug', 'info', 'warn', 'error'];
@@ -42,10 +43,13 @@ export function initLogTailer() {
const originalConsoleLogFunction = originalConsole[level];
originalConsoleLogFunctions[level] = originalConsoleLogFunction;
const overrideMethod = (...args: Array<unknown>) => {
const newConsoleLogFunction = originalConsoleLogFunctions[level];
const message = getStringFromErrorLike(args);
const newLevel = transformLogLevel(level, message);
const newConsoleLogFunction = originalConsoleLogFunctions[newLevel];
const result = newConsoleLogFunction(...args);
logTailers.forEach((handler) => {
handler(level, ...args);
handler(newLevel, ...args);
});
return result;
};
@@ -54,3 +58,19 @@ export function initLogTailer() {
originalConsole[level] = overrideMethod;
}
}
function transformLogLevel(level: LoggerTypes, message: string) {
if (level === 'error') {
// Error comes from one of our dependencies and is not actionable
if (message.includes('ResizeObserver loop limit exceeded')) {
return 'warn';
}
// Axios will create rather unhelpful error messages which
// lead to unactionable tasks, e.g. T150636191
if (message.endsWith('Network Error')) {
return 'warn';
}
}
return level;
}