iosswiftloggingcrashlyticsoslog

How to add different loggers (output destination like files and Crashlytics) for logs created by oslog?


Right now if I change the path of the stddr then my logs won't be going to the console anymore and they would only be going to the log files.

I'm wondering if there is a simple way that I can have them both?

Also is there anyway that I can pass logs generated by OSLog to Crashlytics?


Solution

  • You can only do such if you have a wrapper that manages sending logs to oslog and other loggers. Because anything that writes to "system logs" ie to the apple logging layer is where storage is generally opaque to you: os_log, NSLog, etc.

    You could create a class which not only writes to os_log, but also to a local text file in your documents directory. That way, you can control what's logged to disk, and it's in a format and directory that's readable to you which you control. You could allow users to airdrop the file, have it readable via iTunes/USB, or email.

    Also don't forget to wrap your own logging layer in a background thread/process/task to help with that so it doesn't block the core performance of your app.