Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
_getLogPreStyles = (log, index) => {
let message = log.msg;
// Get log style
let logStyle = InlineStyles.logDefault;
if (LOG_LEVEL_TO_STYLE[log.level]) {
logStyle = LOG_LEVEL_TO_STYLE[log.level];
}
// Lower priority of packager logs
if (log.tag === 'metro' && log.level === bunyan.INFO) {
logStyle = InlineStyles.logDebug;
}
// Expo logs can be "quiet" which formats them the same as packager logs
if (log.name === 'expo' && log.level === bunyan.INFO && log.quiet) {
logStyle = InlineStyles.logDebug;
}
// A big chunk of json is logged right when an app starts. Lower the priority.
if (this._isStartupMessage(log)) {
logStyle = InlineStyles.logDebug;
}
let otherStyles = {};
if (message.includes('Project opened!')) {
otherStyles = InlineStyles.bigLog;
write(record: any) {
if (record.level < bunyan.INFO) {
console.log(record);
} else if (record.level < bunyan.WARN) {
console.info(record);
} else if (record.level < bunyan.ERROR) {
console.warn(record);
} else {
console.error(record);
}
}
}
closeOnExit: false,
level: 'debug',
},
]
: [],
});
export type LogStream = bunyan.Stream;
export type Log = bunyan;
export default {
child: (options: object) => logger.child(options),
notifications: logger.child({ type: 'notifications' }),
global: logger.child({ type: 'global' }),
DEBUG: bunyan.DEBUG,
INFO: bunyan.INFO,
WARN: bunyan.WARN,
ERROR: bunyan.ERROR,
};
this.setState(state => {
let connectedDevices = state.connectedDevices;
let focusedConnectedDeviceId = state.focusedConnectedDeviceId;
for (let i = 0; i < this._deviceLogsToAdd.length; i++) {
let chunk = this._deviceLogsToAdd[i];
if (!connectedDevices[chunk.deviceId]) {
let name = this._getDeviceName(chunk.deviceId, chunk.deviceName);
if (!focusedConnectedDeviceId) {
focusedConnectedDeviceId = chunk.deviceId;
}
connectedDevices[chunk.deviceId] = {
name,
logs: [
{
level: bunyan.INFO,
msg: `Streaming logs from ${name}...`,
time: new Date(),
},
],
};
}
connectedDevices[chunk.deviceId].logs = connectedDevices[chunk.deviceId].logs.concat([
chunk,
]);
}
this._deviceLogsToAdd = [];
return {
focusedConnectedDeviceId,
connectedDevices,
write: (chunk: any) => {
if (chunk.code) {
switch (chunk.code) {
case NotificationCode.START_LOADING:
simpleSpinner.start();
return;
case NotificationCode.STOP_LOADING:
simpleSpinner.stop();
return;
case NotificationCode.DOWNLOAD_CLI_PROGRESS:
return;
}
}
if (chunk.level === bunyan.INFO) {
log(chunk.msg);
} else if (chunk.level === bunyan.WARN) {
log.warn(chunk.msg);
} else if (chunk.level >= bunyan.ERROR) {
log.error(chunk.msg);
}
},
},
'Error',
StyleConstants.colorError
);
this._addLogsForArray(
logs,
notifications.warn,
bunyan.WARN,
'Warning',
StyleConstants.colorWarning
);
this._addLogsForArray(logs, notifications.info, bunyan.INFO, 'Info');
}
if (logs.length === 0) {
logs.push({
level: bunyan.INFO,
msg: 'No notifications right now!',
leftMsg: '',
hasVerticalPadding: true,
});
}
return ;
}
const logWithLevel = chunk => {
if (!chunk.msg) {
return;
}
if (chunk.level <= bunyan.INFO) {
logLines(chunk.msg, log);
} else if (chunk.level === bunyan.WARN) {
logLines(chunk.msg, log.warn);
} else {
logLines(chunk.msg, log.error);
}
};
});
return;
case NotificationCode.STOP_LOADING:
this.setState({
isLoading: false,
});
return;
case NotificationCode.DOWNLOAD:
return;
}
let notificationOptions = {
indefinite: !!chunk.indefinite,
};
if (chunk.level <= bunyan.INFO) {
this._showNotification('info', chunk.msg, notificationOptions);
} else {
this._showNotification('warning', chunk.msg, notificationOptions);
}
},
},
const logWithLevel = (chunk: LogRecord) => {
if (!chunk.msg) {
return;
}
if (chunk.level <= bunyan.INFO) {
if (chunk.includesStack) {
logStackTrace(chunk, log, log.nested);
} else {
logLines(chunk.msg, log);
}
} else if (chunk.level === bunyan.WARN) {
if (chunk.includesStack) {
logStackTrace(chunk, log.warn, log.nestedWarn);
} else {
logLines(chunk.msg, log.warn);
}
} else {
if (chunk.includesStack) {
logStackTrace(chunk, log.error, log.nestedError);
} else {
logLines(chunk.msg, log.error);
if (notifications) {
this._addLogsForArray(
logs,
notifications.error,
bunyan.ERROR,
'Error',
StyleConstants.colorError
);
this._addLogsForArray(
logs,
notifications.warn,
bunyan.WARN,
'Warning',
StyleConstants.colorWarning
);
this._addLogsForArray(logs, notifications.info, bunyan.INFO, 'Info');
}
if (logs.length === 0) {
logs.push({
level: bunyan.INFO,
msg: 'No notifications right now!',
leftMsg: '',
hasVerticalPadding: true,
});
}
return ;
}