A modern, flexible logging tool
NSLogger is a high performance logging utility which displays traces emitted by client applications running on macOS, iOS and Android. It replaces traditional console logging traces (NSLog(), Java Log).
The NSLogger Viewer runs on macOS and replaces Xcode, Android Studio or Eclipse consoles. It provides powerful additions like display filtering, defining log domain and level, image and binary logging, message coloring, traces buffering, timing information, link with source code, etc.
NSLogger feature summary:
Here is what it looks like in action:
And with macOS Mojave and later’s dark mode:
Without any change to your code, all the NSLog()
logs from your application are redirected to the NSLogger desktop viewer. The viewer is found automatically on your network, using Bonjour.
A rich API lets you log messages, binary data or images with a lot of detail. Simple wrappers are available for your convenience:
Swift wrapper API:
import NSLogger
[…]
// logging some messages
Logger.shared.log(.network, .info, "Checking paper level…")
// logging image
Logger.shared.log(.view, .noise, myPrettyImage)
// logging data
Logger.shared.log(.custom("My Domain"), .noise, someDataObject)
Objective-C wrapper API:
#import <NSLogger/NSLogger.h>
[…]
LoggerApp(1, @"Hello world! Today is: %@", [self myDate]);
LoggerNetwork(1, @"Hello world! Today is: %@", [self myDate]);
Download the pre-built, signed version of the NSLogger desktop viewer for macOS. Don’t forget to launch the application on your Mac. It won’t show a window until a client connects to it and starts logging.
If your project is configured to use CocoaPods, just add this line to your Podfile
:
pod "NSLogger"
The above only includes C and Obj-C APIs and is suitable for use in applications without any Swift code.
Swift syntactic sugar APIs are added with the Swift
subspec. If you’re developing code in Swift or a mixed Swift / Obj-C environment, use:
pod "NSLogger/Swift"
Note that you don’t strictly need to include the /Swift
variant for your Swift applications. You can perfectly develop your own extensions that call into NSLogger’s C APIs without using the basic provided ones.
Finally if you are using frameworks or libraries that may use NSLogger, then you can use the NoStrip
variant which forces the linker to keep all NSLogger functions in the final build, even those that your code doesn’t use. Since linked in frameworks may dynamically check for the presence of NSLogger functions, this is required as the linker wouldn’t see this use.
pod "NSLogger/NoStrip"
NSLogger is Carthage-compatible. It builds two frameworks: NSLogger
and NSLoggerSwift
. You’ll need to pick either one (but not both) to use in your application. Both can be used with Swift, the NSLoggerSwift
variant adds a simple Swift layer to make NSLogger easier to use from Swift code. You can perfectly develop your own extensions that call into NSLogger’s C APIs without using the basic provided ones, and just use the NSLogger
framework.
Depending on the framework you choose, your code will need to import NSLogger
or import NSLoggerSwift
. This is a difference with Cocoapods support where you always import NSLogger
.
github "fpillet/NSLogger"
Then run:
$ carthage update
Again, the NSLogger.xcodeproj
top-level project offers two targets (NSLogger
and NSLoggerSwift
). Add the built framework that suits your needs.
Since iOS 14, apps have to request permission to access your local network. To enable NSLogger for iOS 14, you have to update your Info.plist
for development builds to include the following:
<key>NSBonjourServices</key>
<array>
<string>_nslogger._tcp</string>
<string>_nslogger-ssl._tcp</string>
</array>
<key>NSLocalNetworkUsageDescription</key>
<string>Access to the local network for development builds</string>
The first log sent by NSLogger will start the logger, by default on the first Bonjour service encountered. But when multiple NSLogger users share the same network, logger connections can get mixed.
To avoid confusion between users, just add this when you app starts (for example, in the applicationDidFinishLaunching
method:
LoggerSetupBonjourForBuildUser();
Then, in the Preferences pane of the NSLogger.app desktop viewer, go to the Network
tab. Type your user name (i.e. $USER
) in the “Bonjour service name” text field.
This will allow the traces to be received only by the computer of the user who compiled the app.
This only work when NSLogger has been added to your project using CocoaPods.
For example if you don’t want to disable OS_ACTIVITY_MODE for your scheme because you need that logs. And you wanna have only your logs in NSLogger in Swift call init function:
func LoggerInit() {
let pointer = LoggerGetDefaultLogger()
var options = LoggerGetOptions(pointer)
options ^= UInt32(kLoggerOption_CaptureSystemConsole) // disable that option
LoggerSetOptions(pointer, options)
}
When using NSLogger without CocoaPods, add LoggerClient.h
, LoggerClient.m
and LoggerCommon.h
(as well as add the CFNetwork.framework
and SystemConfiguration.framework
frameworks) to your iOS or Mac OS X application, then replace your NSLog() calls with LogMessageCompat() calls. We recommend using a macro, so you can turn off logs when building the distribution version of your application.
For automatic discovery of the desktop viewer, your application must run on a device that is on the same network as your Mac. When your app starts logging, the NSLogger framework automatically (by default) looks for the desktop viewer using Bonjour. As soon as traces start coming, a new window will open on your Mac.
Advanced users can setup a Remote Host / Port to log from a client to a specific host), or specify a Bonjour name in case there are multiple viewers on the network.
The desktop viewer application provides tools like:
Your logs can be saved to a .nsloggerdata
file, and reloaded later. When logging to a file, name your log file with extension .rawnsloggerdata
so NSLogger can reopen and process it. You can have clients remotely generating raw logger data files, then send them to you so you can investigate post-mortem.
Note that the NSLogger Mac OS X viewer requires Mac OS X 10.6 or later.
Apply colors to tags and messages using regular expressions.
To define the color, you can use:
blue
#DEAD88
bold
, for example: bold red
The NSLogger framework runs in its own thread in your application. It tries hard to consume as few CPU and memory as possible. If the desktop viewer has not been found yet, your traces can be buffered in memory until a connection is acquired. This allows for tracing in difficult situations, for example device wakeup times when the network connection is not up and running.
NSLogger is Copyright © 2010-2018 Florent Pillet, All Rights Reserved, All Wrongs Revenged. Released under the New BSD Licence. The NSLogger icon is Copyright © Louis Harboe