Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
write(rec) {
if (rec.level < bunyan.INFO) {
console.log(rec);
} else if (rec.level < bunyan.WARN) {
console.info(rec);
} else if (rec.level < bunyan.ERROR) {
console.warn(rec);
} else {
console.error(rec);
}
}
}
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);
}
}
}
{
level: bunyan.INFO,
msg: `Logs from devices will appear here`,
time: this._startTime,
},
];
if (this.state.expoSdkStatus === Doctor.EXPO_SDK_NOT_INSTALLED) {
logs.push({
level: bunyan.WARN,
msg: `Please run \`npm install --save expo\` and add \`import 'expo'\` to the top of your main file to see device logs.`,
time: this._startTime,
});
} else if (this.state.expoSdkStatus === Doctor.EXPO_SDK_NOT_IMPORTED) {
logs.push({
level: bunyan.WARN,
msg: `Add \`import 'expo'\` to the top of your main file to see device logs.`,
time: this._startTime,
});
} else if (
this.state.isProjectRunning &&
!(this.state.expJson && Versions.gteSdkVersion(this.state.expJson, '7.0.0'))
) {
logs.push({
level: bunyan.WARN,
msg: `To see device logs, make sure your project uses at least SDK 7.0.0 and has a valid exp.json.`,
time: this._startTime,
});
}
return logs;
};
const logWithLevel = chunk => {
if (!chunk.msg) {
return;
}
let colorFn = str => str;
if (chunk.level === bunyan.WARN) {
colorFn = chalk.yellow;
} else if (chunk.level === bunyan.ERROR) {
colorFn = chalk.red;
}
if (chunk.includesStack) {
logStackTrace(chunk, log.withTimestamp, log, colorFn);
} else {
logLines(chunk.msg, log.withTimestamp, colorFn);
}
};
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);
}
},
},
logLeftMsg: {
fontSize: StyleConstants.fontSizeSm,
color: StyleConstants.colorSubtitle,
width: 85,
minWidth: 85,
},
loadingIndicator: {
paddingLeft: StyleConstants.gutterLg,
paddingTop: StyleConstants.gutterLg,
},
};
const LOG_LEVEL_TO_STYLE = {
[bunyan.DEBUG]: InlineStyles.logDebug,
[bunyan.INFO]: InlineStyles.logDefault,
[bunyan.WARN]: InlineStyles.logWarning,
[bunyan.ERROR]: InlineStyles.logError,
};
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,
};
{
type: 'raw',
stream: new ConsoleRawStream(),
closeOnExit: false,
level: 'debug',
},
]
: []),
],
});
logger.notifications = logger.child({ type: 'notifications' });
logger.global = logger.child({ type: 'global' });
logger.DEBUG = bunyan.DEBUG;
logger.INFO = bunyan.INFO;
logger.WARN = bunyan.WARN;
logger.ERROR = bunyan.ERROR;
export default logger;
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);
}
},
},
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);
}
};