Latest 2.0.0
Homepage https://github.com/whitesmith/WSLogger
License MIT
Platforms ios 8.0, requires ARC
Authors

Carthage Compatible
SwiftPM Compatible
CocoaPods Compatible
Swift 3.0
Platforms iOS
Build Status
License MIT

An iOS logger where it’s possible to extend the log functionality.

Usage

For example, create a Logger.swift and add your implementation of WSLoggable:

import WSLogger

extension WSLoggable {
    func log(_ message: String, level: WSLogLevel = .debug, customAttributes: [String : Any]? = nil, className: String = "", fileName: NSString = #file, line: Int = #line, function: String = #function) {
        // Log internally
        let text = WSLogger.shared.log(message, level: level, customAttributes: customAttributes, className: String(describing: type(of: self)), fileName: fileName, line: line, function: function)
        // Log remotely using `text`.
        // Fabric, LogEntries, etc.
    }
}

You can add a typealias to avoid importing the WSLogger on every file:

typealias Loggable = WSLoggable
typealias LoggerOptions = WSLoggerOptions
typealias LogLevel = WSLogLevel

Then use the protocol Loggable where you want. The function log will be accessible:

struct WSTableViewCell: Loggable {
    func configure(viewModel: ViewModel) {
        log("Bind model data with views")
        ...
    }
}

It’s possible to change the log level with LoggerOptions.defaultLevel property. For example, if LoggerOptions.defaultLevel is debug then all the verbose entries will be ignored.

You can add LoggerOptions.defaultLevel = .none to discard any log events on your test suite. It’s also possible ignoring classes with Logger.shared.ignoreClass(WSTableViewCell).

You can execute those operations in debug mode as well. Just write in the console expr -- Logger.shared.ignoreClass(WSTableViewCell).

Extend the log mechanism: example using LogEntries

You can extend the log mechanism as you want. For example, if you want to access the log entries online:

LogEntries dashboard

import Foundation
import WSLogger
import lelib //LogEntries iOS lib

func loggerSetup() {
    LoggerOptions.defaultLevel = .Debug
    WSLogger.shared.traceFile = true
    WSLogger.shared.traceMethod = true
    // LogEntries
    LELog.sharedInstance().token = "XXXX-XXX-XXX-XXXX"
}

extension WSLoggable {
    func log(_ message: String, level: WSLogLevel = .debug, customAttributes: [String : Any]? = nil, className: String = "", fileName: NSString = #file, line: Int = #line, function: String = #function) {
        // Log internally
        let text = WSLogger.shared.log(message, level: level, customAttributes: customAttributes, className: String(describing: type(of: self)), fileName: fileName, line: line, function: function)
        // Log remotely
        LELog.sharedInstance().log(text as NSObject)
    }
}

The complete example is available here.

Installation

WSLogger Carthage

To install it, simply add the following line to your Cartfile:

github "whitesmith/WSLogger"

Then run carthage update.

Follow the current instructions in Carthage’s README
for up to date installation instructions.

WSLogger CocoaPods

To install it, simply add the following line to your Podfile:

pod 'WSLogger'

You will also need to make sure you’re opting into using frameworks:

use_frameworks!

Then run pod install with CocoaPods 1.0 or newer.

Manually

Download all the source files and drop them into your project.

Requirements

  • iOS 8.0+
  • Xcode 8.3 (Swift 3.0)

Contributing

The best way to contribute is by submitting a pull request. We’ll do our best to respond to your patch as soon as possible. You can also submit a new GitHub issue if you find bugs or have questions. :octocat:

Credits

Whitesmith

Checkout the excelent topic on Logging in Swift from Krzysztof Zabłocki.

Latest podspec

{
    "name": "WSLogger",
    "version": "2.0.0",
    "summary": "An iOS logger where it's possible to extend the log functionality",
    "homepage": "https://github.com/whitesmith/WSLogger",
    "license": "MIT",
    "authors": {
        "Ricardo Pereira": "[email protected]"
    },
    "source": {
        "git": "https://github.com/whitesmith/WSLogger.git",
        "tag": "2.0.0"
    },
    "social_media_url": "https://twitter.com/whitesmithco",
    "platforms": {
        "ios": "8.0"
    },
    "requires_arc": true,
    "source_files": [
        "WSLogger/*.{h}",
        "Source/**/*.{h,swift}"
    ],
    "pushed_with_swift_version": "3.0"
}

Pin It on Pinterest

Share This