Sebastian Faltoni Software Architect. Passionate about Clean Code, Tech, Web, AI, .NET, Python, IOT, Swift, SwiftUI and also Blazor

File logging for iOS Apps

37 sec read

Are you looking how to store logs on the device file system? Here I will show you how you can achieve it.

In an App I was developing lately who is an enterprise iOS app with limited connectivity. The requirement was to have logging but not on the network.

My choice was settled on CocoaLumberjack, because it looks mature, and with good features.

If you are using pods, add this to your pod file

pod 'CocoaLumberjack/Swift'

Then run pod install

The setup is simple just add this code to your app.

//add this on your App Delegate import area
import CocoaLumberjack
 
// Then inside you didFiniLaunching
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {

....

   let fileLogger: DDFileLogger = DDFileLogger() // File Logger
   fileLogger.rollingFrequency = 60 * 60 * 24 // 24 hours
   fileLogger.logFileManager.maximumNumberOfLogFiles = 5
        
   DDLog.add(fileLogger)
...

Is simple as it looks. you can also see on which directory logs are stored with the following.

print("logsDirectory" , fileLogger.logFileManager.logsDirectory)

Now you can enjoy your logs file.

You can find CocoaLumberjack on GitHub https://github.com/CocoaLumberjack/CocoaLumberjack

Sebastian Faltoni Software Architect. Passionate about Clean Code, Tech, Web, AI, .NET, Python, IOT, Swift, SwiftUI and also Blazor

A simple extension to use Combine with PromiseKit and…

Because ServiceStack use PromiseKit for it’s async calls on Swift, i made this little extension that convert a PromiseKit request into a Combine publisher....
Sebastian Faltoni
39 sec read

Leave a Reply

Your email address will not be published. Required fields are marked *