You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Print console.log and console.error messages in terminal (--consolelogs) #3169
This has to be re-implemented for use with the Angular CLI. We'd need to inject a client JS file into the Angular dev server and connect to a websocket server running from the Ionic CLI.
Reacted by Ross Bender, Steve Kennedy, Luan Freitas and Szabi
Well, when I'm running on the device I do not even see when there are any errors, the application simply hangs, there is no information to aid the fix. I am even stopped now because there is an error that I can not trace.
changed the title [-]Print console.log and console.error messages in terminal for Angular[/-][+]Print console.log and console.error messages in terminal[/+]on Aug 7, 2018
How do I see logs for an app that is installed on the device via Ionic Pro? I'm not able to inspect a 'deployed' app in the same way I'm able to inspect an app I run on the device via 'ionic cordova run android' .. Please can you suggest a solution?
It would great to have this feature back again. The Safari Debugger is very flakey, it often crashes, doesn't detect device unless you restart. It's much nicer to be able to have a dedicated window on screen that always displays the log output.
Reacted by Luan Freitas, Peter Arends, Henry Cho, Laurent, Ross Bender, DavidTalamona, Alexander Bogdanov and Szymon Stasik
changed the title [-]Print console.log and console.error messages in terminal[/-][+]Print console.log and console.error messages in terminal (--consolelogs)[/+]on Feb 26, 2019
in my terminal. Make sure to change the IP to your own and pick a port at random. This is FAR from a good solution and I make NO promises about the code. I literally wrote that in 5-10 min max, I just wanted a POC. It does work and I can see it being built upon to provide a turnkey solution for this in the future.
I just attempted to use Safari again for debugging and it crashed the window almost immediately 🙄. I am going to upgrade to Mojave sometime soon to see if that improves anything but I don't anticipate it doing so.
Reacted by sjregan, Kai Rauer, Alexander Bogdanov, Kevin and João Pedro Netto
@joshstrange
Thanls a lot for sharing mate. It does work. I'm just wondering, if it took you only 10 min to create this work-around, why does the Ionic Team not look into this issue?
Reacted by Laurent, Ralph Theart and Jess Rasmussen
Here is my modified version that uses the 'flatten' library to prevent circular JSON issues, sends console arguments concatenated, prepends the console method and outputs any caught errors to console.
takeOverConsole() {
const ws = new WebSocket('ws://10.0.1.33:12345')
ws.onopen = () => {
// Web Socket is connected, send data using send()
ws.send('Connected!')
const comn = window.console
if (!comn) {
return
}
const methods = ['log', 'warn', 'error']
for (let i = 0; i < methods.length; i++) {
const original = window.console[methods[i]]
window.console[methods[i]] = function () {
const output = []
try {
// @ts-ignore
for (const argument of arguments) {
output.push(typeof argument === 'string' ? argument : stringify(argument))
}
ws.send(methods[i].toUpperCase() + ': ' + output.join(', '))
} catch (error) {
window.console.error('Websocket Console Error', error)
}
original.apply(window.console, arguments)
}
}
}
ws.onclose = function () {
// websocket is closed.
alert('Websocket Console closed.')
}
}
Reacted by Laurent, Josh Strange, abutizi, Alexander Bogdanov, Kevin and Jess Rasmussen
However I keep getting this message: "Only WebSocket connections are welcome here" on my ionic page when I start listening. Am I doing something wrong?
Insdie websocket console, it prints this:
websocat: WebSocketError: I/O failure
@abutizi no idea sorry, this is the first time I've used websocat. Check your websocket URI and make sure you don't have a proxy messing with your connection.
As of the newest ionic cli it looks like --consolelogs works ("-c" is no longer supported since it is used as shorthand for --configuration it looks like). This is GREAT news but I'm still not seeing errors in the console. So I sometimes get a white screen on device and no output in the terminal. I have to open up safari to see the error. The --consolelogs appears to look like it should be working for "console.error" as well. Any idea why it's not getting printed?
While we wait on a better fix I wanted to throw out a quick and dirty fix for people like me:
Add to node_modules/@ionic/angular-toolkit/assets/consolelogs.js:56 <- The line number might be off, just put it at the top of the for() loop before the msg.data.push(arguments[i]) line.
No promises on if this won't cause other issues but it's working for me (and quite helpful since safari likes to crash as soon as I attach to my app 🙄 ). I am normally the first one to recoil in horror at modifying node_modules but that is normally because it messes with our build server (obviously) but I'm ok with this change since it's just for local development purposes. I hope this helps someone else!
Also HUGE thank you to @dwieeb as without his help and pointing out where the issue was I wouldn't have gone looking for a quick fix. Also thank you for the quick reply and logging that issue!
You can only use Safari to debug / log values in the console if it's on the same version as your phone. Since I do not, like most people, want to update to Catalina and my phone is on iOS 13.3 I can't see my device to show the logs.
This leaves only the option for XCode to debug anything that has to deal with native functionality. This is a huge fail IMHO. I can't believe this has been open for this long.
@selected-pixel-jameson I too am not planning on upgrading to Catalina and I have not yet tried Safari debugging on my phone (Safari debugging is terrible). You can still use the --consolelogs flag which is what I do to get my logs in the terminal.
I redact my post then. I thought this was something else as I was no longer seeing logs when running ionic cordova ios -lc it appears as if the flag has changed. Would be nice to have that in the --help... maybe I just missed it then.
@selected-pixel-jameson Console logs didn't work AFAICT when Ionic 4 launched and they added it after this ticket (or other feedback). Also there is STILL a bug when trying to print errors that does not appear to be a high priority. I have a workaround here: #3169 (comment) -- For myself I use patch-package to fix this in my projects.
Activity
imhoffd commentedon Jul 3, 2018
@GuilhermeBCC Can you explain why these logs are vital for your tests? What sort of testing are you doing?
GuilhermeBCC commentedon Jul 3, 2018
Well, when I'm running on the device I do not even see when there are any errors, the application simply hangs, there is no information to aid the fix. I am even stopped now because there is an error that I can not trace.
imhoffd commentedon Jul 3, 2018
If the webview is loaded, you should be able to attach dev tools to debug issues and see console logs:
iOS: https://beta.ionicframework.com/docs/building/ios#using-safari-web-inspector
Android: https://beta.ionicframework.com/docs/building/android#using-chrome-devtools-to-debug
GuilhermeBCC commentedon Jul 3, 2018
it works and it's great \o/ thanks!
[-]Print console.log and console.error messages in terminal for Angular[/-][+]Print console.log and console.error messages in terminal[/+]Borongaj commentedon Aug 8, 2018
Dev tools are nice, but we have to restart manually everytime we build the app. Sometimes the dev tools window closes immediatly after launch.
Is it normal that Ionic 3 projects don't show logs anymore too ?
imhoffd commentedon Aug 8, 2018
@Borongaj No, it's not normal that Ionic 3 projects stopped logging. If you want, create a new issue.
obkdev commentedon Sep 13, 2018
How do I see logs for an app that is installed on the device via Ionic Pro? I'm not able to inspect a 'deployed' app in the same way I'm able to inspect an app I run on the device via 'ionic cordova run android' .. Please can you suggest a solution?
Thank you!
ludufre commentedon Jan 31, 2019
Just curious: do you plan to implement this in the near future?
sjregan commentedon Feb 12, 2019
It would great to have this feature back again. The Safari Debugger is very flakey, it often crashes, doesn't detect device unless you restart. It's much nicer to be able to have a dedicated window on screen that always displays the log output.
[-]Print console.log and console.error messages in terminal[/-][+]Print console.log and console.error messages in terminal (--consolelogs)[/+]ludufre commentedon Mar 4, 2019
Is there any forecast?
timbru31 commentedon Mar 4, 2019
Given that it's nearly 1 year without any progress, I believe you can't expect a forecast/ETA/release date
7 remaining items
abutizi commentedon Mar 19, 2019
I'm also suffering of the in-ability to show console logs using the -c command. Anyone here found a way that could help a brother out?
joshstrange commentedon Mar 22, 2019
@abutizi I hacked in a VERY rudimentary system using the following code in app.component:
and this tool running:
in my terminal. Make sure to change the IP to your own and pick a port at random. This is FAR from a good solution and I make NO promises about the code. I literally wrote that in 5-10 min max, I just wanted a POC. It does work and I can see it being built upon to provide a turnkey solution for this in the future.
I just attempted to use Safari again for debugging and it crashed the window almost immediately 🙄. I am going to upgrade to Mojave sometime soon to see if that improves anything but I don't anticipate it doing so.
abutizi commentedon Mar 27, 2019
@joshstrange
Thanls a lot for sharing mate. It does work. I'm just wondering, if it took you only 10 min to create this work-around, why does the Ionic Team not look into this issue?
sjregan commentedon Mar 27, 2019
@joshstrange Thanks, great work.
Here is my modified version that uses the 'flatten' library to prevent circular JSON issues, sends console arguments concatenated, prepends the console method and outputs any caught errors to console.
abutizi commentedon Mar 28, 2019
thanks @sjregan
However I keep getting this message: "Only WebSocket connections are welcome here" on my ionic page when I start listening. Am I doing something wrong?
Insdie websocket console, it prints this:
websocat: WebSocketError: I/O failure
sjregan commentedon Mar 29, 2019
@abutizi no idea sorry, this is the first time I've used websocat. Check your websocket URI and make sure you don't have a proxy messing with your connection.
macekCZ commentedon Apr 29, 2019
I develop apps on Windows but testing via DevApp on iPhone ,.. any chance to see debug log?
joshstrange commentedon Jun 19, 2019
As of the newest ionic cli it looks like --consolelogs works ("-c" is no longer supported since it is used as shorthand for --configuration it looks like). This is GREAT news but I'm still not seeing errors in the console. So I sometimes get a white screen on device and no output in the terminal. I have to open up safari to see the error. The --consolelogs appears to look like it should be working for "console.error" as well. Any idea why it's not getting printed?
imhoffd commentedon Jun 19, 2019
@joshstrange Thanks for the report! Looks like we're not serializing Error objects very well. I made an issue for that: ionic-team/angular-toolkit#152
joshstrange commentedon Jun 19, 2019
While we wait on a better fix I wanted to throw out a quick and dirty fix for people like me:
Add to
node_modules/@ionic/angular-toolkit/assets/consolelogs.js:56<- The line number might be off, just put it at the top of thefor()loop before themsg.data.push(arguments[i])line.No promises on if this won't cause other issues but it's working for me (and quite helpful since safari likes to crash as soon as I attach to my app 🙄 ). I am normally the first one to recoil in horror at modifying
node_modulesbut that is normally because it messes with our build server (obviously) but I'm ok with this change since it's just for local development purposes. I hope this helps someone else!Also HUGE thank you to @dwieeb as without his help and pointing out where the issue was I wouldn't have gone looking for a quick fix. Also thank you for the quick reply and logging that issue!
selected-pixel-jameson commentedon Dec 19, 2019
You can only use Safari to debug / log values in the console if it's on the same version as your phone. Since I do not, like most people, want to update to Catalina and my phone is on iOS 13.3 I can't see my device to show the logs.
This leaves only the option for XCode to debug anything that has to deal with native functionality. This is a huge fail IMHO. I can't believe this has been open for this long.
joshstrangetp commentedon Dec 19, 2019
@selected-pixel-jameson I too am not planning on upgrading to Catalina and I have not yet tried Safari debugging on my phone (Safari debugging is terrible). You can still use the
--consolelogsflag which is what I do to get my logs in the terminal.selected-pixel-jameson commentedon Dec 19, 2019
I redact my post then. I thought this was something else as I was no longer seeing logs when running
ionic cordova ios -lcit appears as if the flag has changed. Would be nice to have that in the --help... maybe I just missed it then.joshstrangetp commentedon Dec 19, 2019
@selected-pixel-jameson Console logs didn't work AFAICT when Ionic 4 launched and they added it after this ticket (or other feedback). Also there is STILL a bug when trying to print errors that does not appear to be a high priority. I have a workaround here: #3169 (comment) -- For myself I use patch-package to fix this in my projects.
ludufre commentedon Dec 19, 2019
@selected-pixel-jameson
ionic cordova run ios -l --consolelogs