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
This commit is contained in:
committed by
Facebook GitHub Bot
parent
055b14c6dd
commit
054fbf1298
@@ -23,10 +23,12 @@ import {
|
|||||||
loadProcessConfig,
|
loadProcessConfig,
|
||||||
loadSettings,
|
loadSettings,
|
||||||
setupPrefetcher,
|
setupPrefetcher,
|
||||||
|
Tail,
|
||||||
} from 'flipper-server-core';
|
} from 'flipper-server-core';
|
||||||
import {
|
import {
|
||||||
FlipperServer,
|
FlipperServer,
|
||||||
getLogger,
|
getLogger,
|
||||||
|
LoggerInfo,
|
||||||
isTest,
|
isTest,
|
||||||
Logger,
|
Logger,
|
||||||
parseEnvironmentVariables,
|
parseEnvironmentVariables,
|
||||||
@@ -103,7 +105,16 @@ async function getEmbeddedFlipperServer(
|
|||||||
}
|
}
|
||||||
|
|
||||||
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
||||||
async function getFlipperServer(_logger: Logger): Promise<FlipperServer> {
|
async function getFlipperServer(
|
||||||
|
_logger: Logger,
|
||||||
|
electronIpcClient: ElectronIpcClientRenderer,
|
||||||
|
): Promise<FlipperServer> {
|
||||||
|
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(
|
const flipperServer = await createFlipperServer(
|
||||||
'localhost',
|
'localhost',
|
||||||
52342,
|
52342,
|
||||||
@@ -169,6 +180,18 @@ function getStaticDir(appPath: string) {
|
|||||||
return _staticPath;
|
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.
|
// 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
|
// 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
|
// the redux store and the rest of the world. So we create a delegating logger
|
||||||
|
|||||||
Reference in New Issue
Block a user