Logging on IOS

Logging on IOS

Easier debugging with effective Logging

Logging is a critical aspect of app development on iOS. It helps developers monitor app behaviour, debug issues, and gather essential information for analytics and diagnostics.
In this blog, we will explore logging on iOS, from basic principles to advanced tools, and introduce a lightweight logging framework, TimberIOS, that simplifies logging in Swift projects.

TimberIOS saves you the time required to setup if you want to have a unified but Simplified Logging system for your project maintaining consistency across the project.

It’s built on top of the Apple's Unified Logging system and makes it easier to Log in Swift Projects with an easy and unified approach.

SETUP

To use the Timber IOS Package,

  1. Install TIMBERIOS with Swift Package manager.- the package Link https://github.com/Felix-Kariuki/TimberIOS

  2. In your Project Import TimberIOS and start using

Usage

There are Several Logging levels that you can use and the approach is as demonstrated below:

  1. Error Logs

    Incase you want to log Error messages / logs

     import TimberIOS
    
     Timber.e("An error occurred")
    
  2. Info Logs

     import TimberIOS
    
     Timber.i("Informational message")
    
  3. Warning Logs

     import TimberIOS
    
     Timber.w("This is a warning")
    
  4. Debug Logs

     import TimberIOS
    
     Timber.d("This is a debug message")
    

Timber IOS nomenclature is inspired by the Timber Logging library in android by JakeWharton , and coming from an android background I wanted to maintain the same logging system for both platforms

Best Practices for Logging

1. Use Appropriate Log Levels

  • Debug: For detailed information during development.

  • Info: For general operational messages.

  • Error: For non-critical issues.

  • Fault: For critical errors requiring immediate attention.

2. Avoid Logging Sensitive Data

TimberIOS always mark’s sensitive data as private by default so no need to worry about this.

logger.info("Info: User email \(email, privacy: .private)")

3. Keep Logs Concise

Avoid logging large amounts of data. Focus on key information relevant to debugging or monitoring.

4. Remove Debug Logs in Production

TimberIOS ensures logs are only active in debug builds using #if DEBUG, so you need not worry about this whilst using TimberIOS on your project

5. Monitor Logs in Production

Consider using third party SDK’s like Firebase Crashlytics , Bugfender or Sentry for collecting logs and crash reports.