Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: Unify logging #146

Merged

Conversation

sidferreira
Copy link

Summary:

Based on #95, replaced console.(log|warn|error) by logger.(info|warn|error).
Used regular expressions but everything seems to be working as should.

Test Plan:

All tests are passing, no other change was required.

console.log(` Open ${relativeXcodeProjectPath} in Xcode`);
console.log(' Hit the Run button');
logger.info(chalk.white.bold('To run your app on iOS:'));
logger.info(` cd ${absoluteProjectDir}`);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

logger.info will prepend INFO to the message, we don't want it to be here. Can you fold it down to a single logger.info call with a nice template string inside?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed

@@ -37,7 +38,7 @@ async function logIOS() {

const device = findAvailableDevice(devices);
if (device === undefined) {
console.log(chalk.red('No active iOS device found'));
logger.info(chalk.red('No active iOS device found'));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
logger.info(chalk.red('No active iOS device found'));
logger.error('No active iOS device found');

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed

@@ -33,7 +34,7 @@ function checkAndroid(root) {
*/
function runAndroid(argv: Array<string>, config: ContextT, args: Object) {
if (!checkAndroid(args.root)) {
console.log(
logger.info(
chalk.red(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this should be logger.error without chalk

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed

} else if (result === 'unrecognized') {
console.warn(
logger.warn(
chalk.yellow('JS server not recognized, continuing with build...')
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
chalk.yellow('JS server not recognized, continuing with build...')
'JS server not recognized, continuing with build...'

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this (and similar) still need to be addressed

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed

@sidferreira
Copy link
Author

Cannot call `logger.info` because array type [1] is incompatible with string [2] in array element.

   packages/cli/src/runAndroid/runAndroid.js:138:7
   138|       logger.info(devices);
              ^^^^^^^^^^^^^^^^^^^^

References:
   packages/cli/src/runAndroid/adb.js:37:24
    37| function getDevices(): Array<string> {
                               ^^^^^^^^^^^^^ [1]
   packages/cli/src/util/logger.js:10:34
    10| const info = (...messages: Array<string>) => {
                                         ^^^^^^ [2]

Should we change the type to accept arrays or actually split the parameter?

@@ -47,14 +48,14 @@ function runAndroid(argv: Array<string>, config: ContextT, args: Object) {

return isPackagerRunning(args.port).then(result => {
if (result === 'running') {
console.log(chalk.bold('JS server already running.'));
logger.info(chalk.bold('JS server already running.'));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
logger.info(chalk.bold('JS server already running.'));
logger.info('JS server already running.');

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed

@@ -101,7 +102,7 @@ function buildAndRun(args) {
adbPath
);
}
console.log(chalk.red('Argument missing for parameter --deviceId'));
logger.info(chalk.red('Argument missing for parameter --deviceId'));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
logger.info(chalk.red('Argument missing for parameter --deviceId'));
logger.error('Argument missing for parameter --deviceId');

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed

chalk.yellow('JS server not recognized, continuing with build...')
);
} else {
// result == 'not_running'
console.log(chalk.bold('Starting JS server...'));
logger.info(chalk.bold('Starting JS server...'));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
logger.info(chalk.bold('Starting JS server...'));
logger.info('Starting JS server...');

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@thymikee remove all chalk.bold?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed

@sidferreira
Copy link
Author

sidferreira commented Feb 4, 2019

  • log(chalk.red => error
  • Remove all bold
  • chalk.yellow => warn

console.log(devices);
logger.info(`Could not find device with the id: "${args.deviceId}".`);
logger.info('Choose one of the following:');
logger.info(devices);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please fold it into single logger.error

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed

}
} else {
console.log('No Android devices connected.');
logger.info('No Android devices connected.');
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
logger.info('No Android devices connected.');
logger.error('No Android devices connected.');

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed

Copy link
Member

@thymikee thymikee left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've left a bunch of suggestions in certain places, but they hold true for all the code here. One of the reason we use logger is to get rid of extra chalk styles as they should be controlled uniformly by the logger, so please remove those. Also there are places where error is more appropriate than info – I mark some of them but please review the rest of the diff as well

@thymikee
Copy link
Member

thymikee commented Feb 4, 2019

Should we change the type to accept arrays or actually split the parameter?

just spread the devices:

logger.info(...devices);

@sidferreira
Copy link
Author

module.exports = function copyMiddleware(req, res, next) {
  if (req.url === '/copy-to-clipboard') {
    const ret = copyToClipBoard(req.rawBody);
    if (!ret) {
      logger.warn(chalk.red('Copy button is not supported on this platform!'));
    }
    res.end('OK');
  } else {
    next();
  }
};

error or warn? @thymikee

@thymikee
Copy link
Member

thymikee commented Feb 4, 2019

I'd go with regular warn for now :)

return;
}
hasWarned = true;
console.warn(
logger.warn(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we don't want logger in debugger-ui because it runs in a browser

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed

Copy link
Member

@thymikee thymikee left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

last few bits, and we're good to merge it :)

logger.info('');
logger.info('** INSTALLATION FAILED **');
logger.info('Make sure you have ios-deploy installed globally.');
logger.info('(e.g "npm install -g ios-deploy")');
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we fold this?

@@ -23,13 +23,13 @@ function tryRunAdbReverse(packagerPort: number | string, device: string) {
adbArgs.unshift('-s', device);
}

console.log(chalk.bold(`Running ${adbPath} ${adbArgs.join(' ')}`));
logger.info(chalk.bold(`Running ${adbPath} ${adbArgs.join(' ')}`));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
logger.info(chalk.bold(`Running ${adbPath} ${adbArgs.join(' ')}`));
logger.info(`Running ${adbPath} ${adbArgs.join(' ')}`);

@sidferreira
Copy link
Author

sidferreira commented Feb 4, 2019

react-native-cli/packages/cli/src/init/init.js
  53:3  error  Unused eslint-disable directive (no problems were reported from 'import/no-unresolved')

  // eslint-disable-next-line import/no-unresolved
  const reactNativePackageJson = require('react-native/package.json');

not mine, but it's showing up

@thymikee
Copy link
Member

thymikee commented Feb 4, 2019

53:3 error Unused eslint-disable directive (no problems were reported from 'import/no-unresolved')

Try rebasing/merging master, as after this PR #144 we dropped react-native as a dev dependency

logger.info('Choose one of the following:');
printFoundDevices(devices);
logger.error(`Could not find device with the name: "${args.device}".
Choose one of the following:${printFoundDevices(devices)}`);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

printFoundDevices outputs logs by itself, so this is wrong

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@thymikee I changed it to be a list.
There's another place which the output is a list (I think for Android). I changed to be like this to keep some sort of standard. But LMK if I need to revert.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, that's good (name could be different now, but there's too much changes to this PR already :D) Thanks for bearing with me!

@thymikee thymikee merged commit 486a65a into react-native-community:master Feb 4, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants