From 054fbf129834008cf18b839c3697a38c0c00a817 Mon Sep 17 00:00:00 2001 From: Lorenzo Blasa Date: Wed, 1 Jun 2022 04:37:36 -0700 Subject: [PATCH] Aggregate existing logs from the ones generated by flipper-server Summary: This change aggregates/redirects flipper-server logs with logs generated by the app. This is a great approach, why: As we tail the file, we deserialise the logs, and re-log them using console. This means, that they will be intercepted by the logging infrastructure flipper already has in place which will make these logs go to scribe, error reporting, etc. Reviewed By: passy Differential Revision: D36473790 fbshipit-source-id: a3547c5c8733217c61bb2d9b94990626bbf0a492 --- desktop/app/src/init.tsx | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/desktop/app/src/init.tsx b/desktop/app/src/init.tsx index ca6c2e230..0265db5ed 100644 --- a/desktop/app/src/init.tsx +++ b/desktop/app/src/init.tsx @@ -23,10 +23,12 @@ import { loadProcessConfig, loadSettings, setupPrefetcher, + Tail, } from 'flipper-server-core'; import { FlipperServer, getLogger, + LoggerInfo, isTest, Logger, parseEnvironmentVariables, @@ -103,7 +105,16 @@ async function getEmbeddedFlipperServer( } // eslint-disable-next-line @typescript-eslint/no-unused-vars -async function getFlipperServer(_logger: Logger): Promise { +async function getFlipperServer( + _logger: Logger, + electronIpcClient: ElectronIpcClientRenderer, +): Promise { + const appPath = await electronIpcClient.send('getPath', 'app'); + const staticPath = getStaticDir(appPath); + + const loggerOutputFile = 'flipper-server-log.out'; + tailServerLogs(path.join(staticPath, loggerOutputFile)); + const flipperServer = await createFlipperServer( 'localhost', 52342, @@ -169,6 +180,18 @@ function getStaticDir(appPath: string) { return _staticPath; } +function tailServerLogs(logsPath: string) { + console.info('flipper-server logs located at: ', logsPath); + const tail = new Tail(logsPath); + tail.on('line', (line: any) => { + try { + const loggerInfo: LoggerInfo = JSON.parse(line); + console[loggerInfo.type](loggerInfo.msg); + } catch (_) {} + }); + tail.watch(); +} + // getLogger() is not yet created when the electron app starts. // we can't create it here yet, as the real logger is wired up to // the redux store and the rest of the world. So we create a delegating logger