Skip to content
This repository has been archived by the owner on Jan 18, 2024. It is now read-only.

Commit

Permalink
Address PR feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
fson committed Apr 17, 2020
1 parent 259fd10 commit a6bd7e8
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions packages/dev-server/src/middleware/clientLogsMiddleware.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import http from 'http';
import Log from '@expo/bunyan';

type ConsoleLogLevel = 'info' | 'warn' | 'error' | 'debug';

export default function clientLogsMiddleware(logger: Log) {
return function(
req: http.IncomingMessage & { body?: any },
Expand All @@ -11,7 +13,7 @@ export default function clientLogsMiddleware(logger: Log) {
const deviceId = req.headers['device-id'];
const deviceName = req.headers['device-name'];
if (deviceId && deviceName && req.body) {
_handleDeviceLogs(logger, deviceId.toString(), deviceName.toString(), req.body);
handleDeviceLogs(logger, deviceId.toString(), deviceName.toString(), req.body);
}
} catch (error) {
logger.error({ tag: 'expo' }, `Error getting device logs: ${error} ${error.stack}`);
Expand All @@ -21,30 +23,28 @@ export default function clientLogsMiddleware(logger: Log) {
};
}

function _isIgnorableBugReportingExtraData(body: any[]) {
function isIgnorableBugReportingExtraData(body: any[]) {
return body.length === 2 && body[0] === 'BugReporting extraData:';
}

function _isAppRegistryStartupMessage(body: any[]) {
function isAppRegistryStartupMessage(body: any[]) {
return (
body.length === 1 &&
(/^Running application "main" with appParams:/.test(body[0]) ||
/^Running "main" with \{/.test(body[0]))
);
}

type ConsoleLogLevel = 'info' | 'warn' | 'error' | 'debug';

function _handleDeviceLogs(logger: Log, deviceId: string, deviceName: string, logs: any) {
function handleDeviceLogs(logger: Log, deviceId: string, deviceName: string, logs: any) {
for (let i = 0; i < logs.length; i++) {
const log = logs[i];
let body = typeof log.body === 'string' ? [log.body] : log.body;
let { level } = log;

if (_isIgnorableBugReportingExtraData(body)) {
if (isIgnorableBugReportingExtraData(body)) {
level = 'debug';
}
if (_isAppRegistryStartupMessage(body)) {
if (isAppRegistryStartupMessage(body)) {
body = [`Running application on ${deviceName}.`];
}

Expand Down

0 comments on commit a6bd7e8

Please sign in to comment.