Skip to content

0xced/XCDLumberjackNSLogger

Repository files navigation

About

Platform Pod Version License

XCDLumberjackNSLogger is a CocoaLumberjack logger which sends logs to NSLogger.

Requirements

  • Runs on iOS 8.0 and later
  • Runs on OS X 10.10 and later
  • Runs on tvOS 9.0 and later

Installation

XCDLumberjackNSLogger is available through CocoaPods and Carthage.

CocoaPods:

pod "XCDLumberjackNSLogger", "~> 1.1"

Carthage:

github "0xced/XCDLumberjackNSLogger" ~> 1.1

Usage

XCDLumberjackNSLogger is fully documented.

Binding to User Defaults

The easiest way to use XCDLumberjackNSLogger is to bind a logger to a user defaults key.

[XCDLumberjackNSLogger bindToBonjourServiceNameUserDefaultsKey:@"NSLoggerBonjourServiceName" configurationHandler:nil];

Anytime you change the user defaults key (NSLoggerBonjourServiceName in this example), the logger reconnects to the desktop viewer with the given service name.

You can change the service name user defaults manually with

[[NSUserDefaults standardUserDefaults] setObject:serviceName forKey:@"NSLoggerBonjourServiceName"];

or with a Settings bundle:

<dict>
	<key>AutocapitalizationType</key>
	<string>None</string>
	<key>AutocorrectionType</key>
	<string>No</string>
	<key>DefaultValue</key>
	<string></string>
	<key>IsSecure</key>
	<false/>
	<key>Key</key>
	<string>NSLoggerBonjourServiceName</string>
	<key>KeyboardType</key>
	<string>Alphabet</string>
	<key>Title</key>
	<string>NSLogger Service Name</string>
	<key>Type</key>
	<string>PSTextFieldSpecifier</string>
</dict>

This is very handy to get logs even in the App Store with zero overhead. Just open the settings of your app (in the iOS Settings app) and change the service name to automatically activate the logger.

When debugging with Xcode you can set -NSLoggerBonjourServiceName "Your Service Name" in Arguments Passed On Launch in your scheme to set the NSLoggerBonjourServiceName user default.

Simply send logs to NSLogger

[DDLog addLogger:[XCDLumberjackNSLogger new]];

Configuring a bonjour service name

NSString *bonjourServiceName = [[[NSProcessInfo processInfo] environment] objectForKey:@"NSLOGGER_BONJOUR_SERVICE_NAME"];
[DDLog addLogger:[[XCDLumberjackNSLogger alloc] initWithBonjourServiceName:bonjourServiceName]];

Translating contexts to tags

XCDLumberjackNSLogger *logger = [XCDLumberjackNSLogger new];
logger.tags = @{ @80 : @"CocoaHTTPServer", @((NSInteger)0xced70676) : @"XCDYouTubeKit" };
[DDLog addLogger:logger];

Configuring a viewer host

XCDLumberjackNSLogger *logger = [XCDLumberjackNSLogger new];
LoggerSetViewerHost(logger.logger, CFSTR("10.0.1.7"), 50000);
[DDLog addLogger:logger];

Contact

Cédric Luthi

License

XCDLumberjackNSLogger is available under the MIT license. See the LICENSE file for more information.