There is way to log ionic app to file?

hi guys i’m dev an ionic 3 app, so i use ionic background mode plugin to keep app running in background, after 2 or 3 h of running in background my app crash and it s not available it closed auto when i move fourground app is not here, so i want to use some kind of logger to log errror to a file, then i can read this log file to catch the error, so my question is there is way to do that.
thnk u so much guys,