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