Usage
Quick Start
LogKit makes it easy to get started logging!
- Install LogKit
import LogKit
- Create a Logger
Note: If you installed LogKit by including its source directly within your project, there is no need to
import LogKit
(in fact, you will not be able to). Skip that step and just create a Logger.
To get started right away, install LogKit and follow the Simple Example code below. Later, it’s easy to add more Endpoints by just modifying the Logger’s initialization. All logging calls will begin outputting to the new Endpoints the next time your application is run.
Simple Example (in iOS)
AppDelegate.swift
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
import UIKit
import LogKit
let log = LXLogger()
@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate, UISplitViewControllerDelegate {
// ...
func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject : AnyObject]?) -> Bool {
log.debug("Hello Internet!")
return true
}
}
This simple example initializes a Logger with a standard Console Endpoint. Lines 2, 4, and 12 contain the relevant code for getting LogKit set up quickly and making your first Log Entry.
Because the Logger instance log
is created as a global, you may now make logging calls from any of your project’s source files.
Advanced Usage
The basics of LogKit don’t change, but its real power comes from using Endpoints other than the console. LogKit allows you to write Log Entries to as many Endpoints as desired. Each of these Endpoints can be customized to log in different formats, or set to accept different Priority Levels.
Complex Example (in OS X) with Multiple Endpoints
AppDelegate.swift
This complex example initializes a Logger with several Endpoints:
- a Serial Console Endpoint that asynchronously outputs Entries of all Priority Levels, using a shortened time-only custom date format and a concise custom Entry format.
- a File Endpoint that saves to a
logs
directory inside the user’s Documents directory, only outputting Entries of Priority LevelNotice
and above, using a very detailed custom Entry format.
These are just two of several Endpoints that LogKit includes. See the Endpoint documentation for other Endpoints that LogKit includes, and for information on creating your own Endpoints.