Skip to content
Holló András edited this page Jan 15, 2019 · 2 revisions

Logging

Starting to use Journal is easy. Just add the Loggers and LoggingDetailProviders which you would like to use, and then use the five logging functions to log on the different logging levels:

func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
    JournalProvider.shared.journal.add(logger: BonjourLogger())
    JournalProvider.shared.journal.add(logger: ConsoleLogger())
    JournalProvider.shared.journal.add(loggingDetailProvider: TimeLoggingDetailProvider())
    JournalProvider.shared.journal.add(loggingDetailProvider: ClassLoggingDetailProvider())
    
    return true
}

Logging from a class only needs the Journal module to be imported, then you can use the macro functions:

import Journal

class ExampleViewController: UIViewController {

    override func viewDidLoad() {
        super.viewDidLoad()
        
        error("Failed to load ExampleViewController", .customError)
        warning("Failed to load some resource")
        info("Example screen visible")
        debug("ExampleViewController was loaded")
        verbose("Called viewDidLoad()")
    }
    
}

Clone this wiki locally