skip to Main Content

I am developing a react-native mobile application and testing on both Android and iOS simulators at the same time. The thing is when we run npx react-native start it starts the metro bundler and then asks for android or iOS commands. When we select one of them it starts the app and prints logs for it but when at the same time we start the other it gives logs in the same terminal window. This way I am not able to figure out from which platform the logs are coming.

I want to view both platform logs differently. Is there a way or other methods to print logs separately?

2

Answers


  1. TLDR; You can change the port number for iOS and keep the same port for android. Then run two terminals with each and you should be able to see logs separately.

    Run for android

    1. Build for android and let it run

    Running different for the iOS

    1. Go to your ios/[projectName].xcodeproj/project.pbxproj file and
      search for 8081.

    2. Replace it with 8082

    3. then go to different terminal than the one running android and do yarn start –port 8082

    Login or Signup to reply.
  2. The quickest way, in my opinion, would be to use the Platform method from react-native.

    UseCase

    import { Platform } from 'react-native';
    
    ...
    
     if (Platform.OS === "ios") {
        console.log("Hello from iOS");
     } else {
        console.log("Hello from other");
     }
    
    ...
    
     {
       Platform.OS === "ios" ? <Some iOS component /> : <Some Android component/>
     }
    
    ...
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search