Skip to content
/ logkit1 Public
forked from logkit/logkit

An efficient logging library for OS X, iOS, watchOS, and tvOS – written in Swift. Log to console, file, HTTP service, or your own endpoint. Simple to get started, but smartly customizable.

License

Notifications You must be signed in to change notification settings

sokol8/logkit1

 
 

Repository files navigation

LogKit

http://www.logkit.info/

LogKit is a logging framework built to be simple to get started with, efficient to execute, safe for shipping code, and extensible for flexibility. It is written in pure Swift and is suitable for OS X, iOS, tvOS, and watchOS application logging. For a developer looking for more power than print(), LogKit takes just a moment to get started with, and comes ready to log to the console, a file, an HTTP service, or all three. Need to log to somewhere else? Defining your own Endpoint is easy too.

This readme contains just a few tips to get you started with LogKit. To learn everything else, check the project website.

Build Status CocoaPods Carthage compatible

Contents

Features

Requirements

  • Project targeting OS X 10.9+, iOS 7+, tvOS 9+, or watchOS 2+
  • Xcode 7.3 and Swift 2.2

Installation

There are a few ways to install LogKit. Below are some tips, but for full details, see the installation guide.

Note: For some reason, CocoaPods removes the CocoaPods and Carthage installation instructions from this readme displayed on their website. Please visit the installation guide if you do not see these installation options.

CocoaPods

Supports iOS 8+, OS X 10.9+, tvOS 9+, watchOS 2+

Include LogKit in your Podfile:

use_frameworks!
pod 'LogKit', '~> 2.3'

For more information on getting started with CocoaPods, read the guide.

Carthage

Supports iOS 8+, OS X 10.9+, tvOS 9+, watchOS 2+

Include LogKit in your Cartfile:

github "logkit/logkit" ~> 2.3

For more information on getting started with Carthage, visit the repo.

Embedded Framework

Supports iOS 8+, OS X 10.9+, tvOS 9+, watchOS 2+

Include LogKit.xcodeproj within your project (second level, below your project root, as a sub-project). Select your target, and add LogKit as an Embedded Binary in the General tab. Pick the appropriate LogKit framework for your target’s OS. Be sure to select the framework, not the tests.

Source

Supports iOS 7+, OS X 10.9+, tvOS 9+, watchOS 2+

Integrating the LogKit source is the only way to include LogKit in projects targeting iOS 7. When this installation method is used, skip the import LogKit.

Add all of the .swift files found in the Sources directory to your project. No other steps are necessary for installation.

Migrating from LogKit 1

If you have previously used LogKit 1, most of LogKit 2 will be familiar to you. However, many objects have updated names and initializers. Please review the ChangeLog and read the Migration Guide to update your code for LogKit 2.

Usage

LogKit is easy to get started with. Everything comes with convenience initializers that require the bare minimum arguments (usually no arguments) and provide sensible defaults. Get started quickly, and then customize as desired later.

Use the Quick Start below to get started now, then check out the usage guide for details of everything LogKit can do.

Quick Start

Near the top of your AppDelegate.swift file, add the following two lines:

import LogKit

let log = LXLogger()

This will import the LogKit framework and create a global Logger instance. This Logger will initialize with a standard Console Endpoint set to log all messages in the default format. Since the Logger instance is created in the global scope, you should only create it once (AppDelegate.swift is the best place).

You can now log from anywhere in your project:

log.info("Hello Internet!")

// 2015-06-25 07:36:01.638000 [INFO] applicationDidFinishLaunching <AppDelegate.swift:23> Hello Internet!

Now you're logging! You can use the debug, info, notice, warning, error, and critical Logger methods.

Additional Endpoints

If you wanted to log to a file as well as the console, and you wanted the file to only receive notice and higher Log Entries, you could set your logger up like this:

import LogKit

let log = LXLogger(endpoints: [

    LXConsoleEndpoint(),

    LXFileEndpoint(
        fileURL: NSURL(string: /* Path to your log file */),
        minimumPriorityLevel: .Notice
    ),

])

You can add and configure as many Endpoints as desired, such as the included File and HTTP Service Endpoints. You can also completely customize the format in which Log Entries are written to each Endpoint.

Formatting

Each Endpoint has a property named dateFormatter that controls how an Entry's dateTime property will be formatted. It accepts an LXDateFormatter instance and is usually set at initialization time.

let log = LXLogger(endpoints: [

    LXConsoleEndpoint(
        dateFormatter = LXDateFormatter(formatString: "HH:mm:ss.SSS")
    ),

])

Each Endpoint also has a property named entryFormatter that controls how an Entry will be converted to a string for output. It accepts an LXEntryFormatter instance and is also usually set at initialization time.

let log = LXLogger(endpoints: [

    LXConsoleEndpoint(
        entryFormatter = LXEntryFormatter({ entry in
            return "\(entry.dateTime) [\(entry.level.uppercaseString)] \(entry.message)"
        })
    ),

])

See the Entry Formatting documentation for more details on formatting, available Log Entry properties, and LXEntryFormatter.

Contributing

LogKit welcomes contributions! Please see CONTRIBUTING.md for more info.

License

LogKit is licensed under the permissive ISC License.

About

An efficient logging library for OS X, iOS, watchOS, and tvOS – written in Swift. Log to console, file, HTTP service, or your own endpoint. Simple to get started, but smartly customizable.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Swift 98.0%
  • Other 2.0%