Category Archives: Life Utility

things useful for my and, hopefully, your daily life.

NSLogger viewer architecture

Whew, two months went by like a bullet. Previously, I wrote a post about what NSLogger is, and why we should exploit it to solve a problem. (About a month ago, even HN talked about NSLogger.)

In order to recap, NSLogger is a very powerful utility that collects logs from your application and provides you rich tool sets to analyze them. My goal is to take the power of NSLogger outside your cubicle to monitor how your app really behaves in unfabricated environments.

NSLogger comes with two parts; libraries for clients (iOS & Android. Yes, it does cover android.), a viewer on OSX. All we need is an iPad Viewer app we can carry outside. OSX viewer is thus a good place to start looking since it is written in same language (Object-C), and shares mostly the same ground with iOS.

So here comes an overview of OSX viewer.

An overview of NSLogger

Model
The viewer is, in essence, a server application which accepts logs from client via stream sockets. It is built in classic MVC pattern having abstracted transports, connections, and log message as model.

The viewer supports three different types of streams (non-secure Bonjour, secure Bonjour with SSL, and direct TCP/IP) and abstracts them in LoggerTransport. Each transport runs its own thread managing client connections with LoggerConnection. A connection then collects and handles each log message with LoggerMessage.

Once instantiated, transports are there to be kept running throughout the life-cycle of the viewer. Meanwhile, a connection will get spawned and removed for each run of a client. If we are to look at how they fit altogether from 10,000 feet, it should look like below.

NSLogger message flow

I believe the setup of model layer part is nicely done, and, at some degree, it is beautiful. The beauty is two folded.

1) First one being that with each layer of abstraction, we can expand or modify to totally different types of connections without too much hassle. Not a lot of network libraries get this right; some being too complicated, or some being too poorly constructed to see it through.

2) With each transport running its own thread and especially its own run-loop, stream events do not get in UI events and vice versa. You’d never miss a stream event just because you touch a cell too long. Plus, we can set up as many transports as we need and no stream event will interfere another as transports are all separated in their own thread and run-roop. Imagine you have ten stream sockets all running on main thread’s run loop. What mayhem are you willing to go though? This seems really no-brainer, but believe me. Even the most popular socket libraries are not built in this way.

Controller
NSLogger Controller

LoggerDocument, a NSDocument subclass, is controller part of OSX viewer. It sticks to the idea ‘fat model, thin controller’, and really carries out. All the heavy lifting is done in model layer and LoggerDocument only routes the messages to view layer.

Each LoggerDocument instance organizes log messages and related views in the context of a client’s activity. LoggerDocument holds all the connections from a single client, and a connection holds all the log messages for a run. If you’re to navigate from a connection to another, you are effectively navigating log messages from one run to another. If you jump from a LoggerDocument to another, you actually move from an activity of a single client to that of another.

Looking down from LoggerDocument, you can see it really represents a whole collection of a client’s activity. This enables the Viewer to have multiple clients connected simultaneously, and to manage them in very organized fashion.

View
NSLogger View

Finally, the view. LoggerWindowController, a subclass of NSWindowController, forms 1 to 1 relationship between LoggerMessageCell and LoggerMessage. LoggerMessageCell then draws LoggerMessage’s content. Simple as that. The thing that makes interesting is how LoggerMessage never gets opened between LoggerTransport and LoggerMessageCell. If you are with me until this point, you can see the whole OSX viewer really comes down to two parts; one that handles socket stream and unpacks raw log, and one that displays the unpacked message. You can take the two parts and put them together as an app, and none will stop you.

The structure in between the two parts, however, keeps collected data very neatly organized, and enables further modification/maintenance without headache. NSLogger OSX viewer really is an exemplary case to carefully study MVC pattern as well as handling of socket stream. I was blown away as soon as I found this was BSD licensed opensource.

In next post, I will describe how to setup iOS keychain to handle self-signed cert to open SSL connections. Please consider subscribing my blog as more awesome stuffs are already in pipeline, and dropping a word to Florent, who single-handedly made all these possible.

* Update : Controller and View parts were added.

Caught at the scene

*This is the first post of series I am going to write. The series is about mobile, all-out-in-the-field logging that might help app developers.

It was back in 2010 when I worked on a location based iOS app. Building the app and its backend altogether was crash-tastic overall, but I managed to come out intact, mostly.

One thing, however, really cornered was logging out in the field. Basically, whenever I took a device outside with my latest build on, the device transformed into a mere consumer gadget. I wanted to know everything that was going on my app right at the spot; ‘is network thread properly handling task queue?’, ‘does location scheduler properly catch input?’, and many more. The device only told me, for example, there were 18 vanues I might be interested. Vanues my ass!!!

I did not want to go back to check if all connections to server went through ok from outside. I did not like to be bothered with a console blocking my pretty app screen telling me things were ok. Nonetheless, I wanted to catch everything right at the moment with ease as they happened without any stunt, y’know? I was a stubborn believer of developer experience (DX), and I still am! As far as I can tell, nothing, I mean not-a-thing, remotely came close to my reach back then. Bummer!

S&W handcuffs. http://www.flickr.com/photos/37815348@N00/5398546351/

Fast forward 2012, I was staring at a websocket library, and I realized it just needed to be re-written so bad. I would do that with smile on my face all the way but on one condition. I needed a good logger library. Like Quinn “the Eskimo” said in WWDC I needed a good logger to come out network mayhem in one piece. There are many options, but I believe only one comes out on top.

It is dubbed as “NSLogger” and written by Florent Pillet.

NSLogger screenshot

In short words, NSLogger is “NSLog + Console” on steroid. NSLogger is basically a server-client logging pair that provides you clients for two major mobile platforms and a separate logger viewer. With the viewer, you can filter log messages however you want as you go.

Here comes a nice introduction by Matthew Burke.

Surely, that is not the end of story. The amazing part is NSLogger not only makes your logging life easy, but also has every element that could finally give us a field logger I was so badly looking for back in 2010. Just about everything we need is right in one place. All we need is some good hard work, and we will have a different notch of mobile app development experience.

If you have come down this far, please consider subscribing my blog, and drop a word to ‘da man’, Florent.

Time to go to work. Stay tuned.

Aggression Test v1.1 is submitted for approval

Version 1.1 of Aggression Test is submitted. After getting lots of muscle on Cocoa and iOS, I could literally see tons of improvements I can make. Since I have few other balls up in the air, I only rebuild application structure and add two important new features: Admob and Facebook sharing.

Facebook sharing will let you share the test result on facebook. Simple and ubiquitous as Facebook is. Admob is there for helping me get some financial aid. Yes, that means Aggression Test is going to be free from version 1.1.

As soon as Aggression Test gets approved, I’ll post few more details! Stay tuned!

Aggression Test v1.0

Screenshot 2009.06.15 14.19.43

“Argghhh…”

Yeah, I know, some of us (please don’t look at me :p) are more physically aggressive than others…

In a recent study, Dr. Peter Hurd from University of Alberta measured the fingers of 300 students at the university. Dr. Peter then reveals that the shorter the index finger of a man is to the ring finger, the more physically aggressive he would be.
Although his research of index finger to ring finger ratio does not show how verbally aggressive one might be, he says the ratio surely shows a large part of one’s personality.
Professor John Manning from the University of Central Lancashire also points that prenatal testosterone exposure in the womb would greatly impact a man’s finger length as well as his physical characteristics.
“I could predict reasonably well who was going to win based on their finger length”, said Prof. John.
“Finger length ‘key to aggression’ “ -BBC- (http://news.bbc.co.uk/2/hi/health/4314209.stm)
Would you like to find out how aggressive you really are?
Simply place your index finger tip and ring finger tip on the iphone screen. “Aggression Test” will immediately show you the ratio between the two fingers, which helps you determine the hidden physical characteristic!
Search for other apps:
Picky Finger
Keyword: Aggression, Wining, Violence, Physical, Anger, Index finger, Ring finger, Testosterone, Physical characteristics.
SKU Number : STKIM002AGGTEST

In a recent study, Dr. Peter Hurd from University of Alberta measured the fingers of 300 students at the university. Dr. Peter then reveals that the shorter the index finger of a man is to the ring finger, the more physically aggressive he would be.

Although his research of index finger to ring finger ratio does not show how verbally aggressive one might be, he says the ratio surely shows a large part of one’s personality.

Professor John Manning from the University of Central Lancashire also points that prenatal testosterone exposure in the womb would greatly impact a man’s finger length as well as his physical characteristics.

“I could predict reasonably well who was going to win based on their finger length”, said Prof. John.

“Finger length ‘key to aggression’ “ -BBC-

Would you like to find out how aggressive you really are?  Simply place your index finger tip and ring finger tip on the iphone screen. “Aggression Test” will immediately show you the ratio between the two fingers, which helps you determine the hidden physical characteristic!

App_Store_badge_0708

Hooray! My first app is away!

screenshot-2009-05-25-15-03-55screenshot-2009-05-25-15-08-19screenshot-2009-05-25-15-05-29

Have you felt like a little help when it comes down to find who’s paying for the next round? look no further. “Picky Finger” is your best bet when it comes down to withdraw massive financial resource from your buddies!

Here comes how it works. You choose how many people to strip off. At this point there are three selection screens randomly generated. That means some might appears more frequently than others but it will eventually level off.  Then put all participants index (please, for the sake of civilization.) finger on the screen.  After three seconds, selection will begin and you will find out who’s up for the next round. Oh, here is caveat. *YOU* could be the one so…prepare from the get-go.

A little bit of story behind scene? Aye-aye, no problem, captain. When I searched some app that would do heavy-lifting for “hey, look, mah ipod says you need to pay! look here! see?”-part, there really wasn’t much of choices. I thought that was good point to start digging into the world of iphone app, and installed Xcode and other applications.  And here it comes…finally!

Yeah few more ‘picking’ could be done, and graphic could be improved, but they are left to be completed within up-coming weeks. So, don’t go away!

App_Store_badge_0708

Oh, by the way, I have borrowed  a lot of ideas from Scott Stevensonand Patrick Geiller. Thank you so much folks!