Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cordova/iOS: Retrieving Console Log from Release Build?

Tags:

ios

cordova

I am attempting to debug an issue with the release/TestFlight build of my app. It is built with Cordova 7.1.0 and cordova-ios 5.1.1. It works fine when deployed to a device/simulator in debug mode, but the release build from TestFlight hangs on the splashscreen. I suspect something in the startup routine is failing, but there is nothing in the device log. I would really like to see the console log from the web view -- is it possible to redirect my app's console logging to the device log so I can get a better picture of what's happening?

like image 476
bjanaszek Avatar asked Nov 20 '25 15:11

bjanaszek


1 Answers

Unfortunately there is no way to get console logs from the app. However, you can utilize or build an API endpoint and overload console.log to both output to the console (so you can see it when dev testing) and to the API endpoint (so you can see what may be happening in production).

The following is just a pretty basic example, but just intended to give you an idea—at least from the front-end—of what you'd be looking at.

window.LogToConsole = window.console.log;
window.console.log = (message) => {
  window.LogToConsole(new Date, message);
  const data = {
    type: "LOG",
    data: mesage,
  };
  fetch('https://api.mydomain.tld/v1/log',
    {
    method: 'POST',
    headers: {
      'Content-Type': 'application/json',
      'Authorization': `Bearer ${userToken}`
    },
    body: JSON.stringify(data) 
  });
};

window.ErrorToConsole = window.console.error;
window.console.error = (message) => {
  window.ErrorToConsole(new Date, message);
  const data = {
    type: "ERROR",
    data: mesage,
  };
  fetch('https://api.mydomain.tld/v1/log',
    {
    method: 'POST',
    headers: {
      'Content-Type': 'application/json',
      'Authorization': `Bearer ${userToken}`
    },
    body: JSON.stringify(data) 
  });
};

Your API endpoint could either utilize a database or a simple file log, that's totally up to you. Get creative with it! I hope this idea helps.

like image 95
Jay V Avatar answered Nov 23 '25 04:11

Jay V