Skip to content

markuswinkler/XCGLoggerNSLoggerConnector

Repository files navigation

Version License Platform

#XCGLoggerNSLoggerConnector #####By: Markus Winkler

###tl;dr Adds NSLogger support (with images) to XCGLogger.

###Compatibility

XCGLoggerNSLoggerConnector works for iOS projects. It is a Swift library intended for use in Swift projects.

###How to Use

In your AppDelegate, declare a global constant to the default XCGLogger instance.

import XCGLogger
import NSLogger
import XCGLoggerNSLoggerConnector

let log: XCGLogger = {
    let log = XCGLogger.defaultInstance()
    log.setup(.Debug, showThreadName: false, showLogLevel: true, showFileNames: true, showLineNumbers: true, writeToFile: nil, fileLogLevel: .Debug)

    // NSLogger support
    // only log to the external window
    LoggerSetOptions(LoggerGetDefaultLogger(), UInt32( kLoggerOption_BufferLogsUntilConnection | kLoggerOption_BrowseBonjour | kLoggerOption_BrowseOnlyLocalDomain ))
    LoggerStart(LoggerGetDefaultLogger())
    log.add(destination: XCGNSLoggerLogDestination(owner: log, identifier: "nslogger.identifier"))

    return log
}()

You can also specify to display inline the file & function name (personal preference, makes it slightly easier to read where the call is coming from).

    log.add(destination: XCGNSLoggerLogDestination(owner: log, identifier: "nslogger.identifier", addInlineDebugInfo: true))

Now all levels accept an UIImage as a parameter and will output the content to the NSLogger window as an image.

log.verbose(image)
log.debug(image)
log.info(image)
log.warning(image)
log.error(image)
log.severe(image)

There is a new filter command, "customLabel". You can use that one to add your own label to filter later on in the NSLogger client. The default value is "image" for image and "string" for string. Use it to distinguish between different kinds of images or outputs (e.g. database results)

log.customLabel(image, label: "facebook icon")
log.customLabel(String(databaseOutput), label: "Database")

Note: the logLevel for customLabels is Info (3)

###References

You can find more info on XCGLogger/NSLogger (documentation and setup) here: XCGLogger: https://github.com/DaveWoodCom/XCGLogger NSLogger: https://github.com/fpillet/NSLogger

###Change Log

  • Version 0.4.0: (2018/10/02) - Update for Swift 4.2
  • Version 0.3.2: (2017/05/23) - Updated first parameter of XCGLogger extension functions in order to override correctly the updated XCGLogger version
  • Version 0.3.1: (2016/12/08) - removed 2 compiler warnings
  • Version 0.3.0: (2016/12/08) - Xcode 8.1 support. Upgrade to iOS 9.
  • Version 0.2.0: (2016/11/23) - Update for Swift 3
  • Version 0.1.4: (2016/08/23) - added XCGLogger limit <= 3.3 since any version above will break this connector
  • Version 0.1.3: (2016/06/08) - fixes
  • Version 0.1.2: (2016/02/15) - added a switch to display additional debug info inline
  • Version 0.1.1: (2015/11/20) - Initial Release