This repository has been archived by the owner on Nov 22, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 958
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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
- Loading branch information
1 parent
8f5fcf9
commit a9b17ac
Showing
3 changed files
with
91 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
/** | ||
* Copyright (c) Meta Platforms, Inc. and affiliates. | ||
* | ||
* This source code is licensed under the MIT license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
* | ||
* @format | ||
*/ | ||
|
||
import {getStringFromErrorLike, LoggerTypes} from 'flipper-common'; | ||
|
||
const logLevels: LoggerTypes[] = ['debug', 'info', 'warn', 'error']; | ||
|
||
export type LogTailer = (level: LoggerTypes, ...data: Array<any>) => void; | ||
|
||
const logTailers: LogTailer[] = []; | ||
|
||
export function addLogTailer(handler: LogTailer) { | ||
logTailers.push(handler); | ||
} | ||
|
||
export function initLogTailer() { | ||
const originalConsole: {[key: string]: any} = console; | ||
//store the raw console log functions here | ||
const originalConsoleLogFunctions: {[key: string]: (...args: any) => void} = | ||
{} as { | ||
[key: string]: (...args: any) => void; | ||
}; | ||
// React Devtools also patches the console methods: | ||
// https://github.com/facebook/react/blob/206d61f72214e8ae5b935f0bf8628491cb7f0797/packages/react-devtools-shared/src/backend/console.js#L141 | ||
// Not using a proxy object here because it isn't compatible with their patching process. | ||
// Instead replace the methods on the console itself. | ||
// Doesn't matter who patches first, single thread means it will be consistent. | ||
for (const level of logLevels) { | ||
const originalConsoleLogFunction = originalConsole[level]; | ||
originalConsoleLogFunctions[level] = originalConsoleLogFunction; | ||
const overrideMethod = (...args: Array<unknown>) => { | ||
const message = getStringFromErrorLike(args); | ||
const newLevel = transformLogLevel(level, message); | ||
|
||
const newConsoleLogFunction = originalConsoleLogFunctions[newLevel]; | ||
const result = newConsoleLogFunction(...args); | ||
logTailers.forEach((handler) => { | ||
handler(newLevel, ...args); | ||
}); | ||
return result; | ||
}; | ||
|
||
overrideMethod.__FLIPPER_ORIGINAL_METHOD__ = originalConsoleLogFunction; | ||
originalConsole[level] = overrideMethod; | ||
} | ||
} | ||
|
||
function transformLogLevel(level: LoggerTypes, message: string) { | ||
if ( | ||
level === 'error' && | ||
message.includes('ResizeObserver loop limit exceeded') | ||
) { | ||
return 'warn'; | ||
} | ||
|
||
return level; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters