Objective-C Logging With SOSmax

| Comments

SOS Logging

i’ve been using SOSmax for a while in my flash projects and i can tell you, it rocks!!, it’s a very handy debugger tool for developers, i found that someone already has created a class for Objective-C called SOSLog and comes with the following features:

  • Different log levels You can use the levels Trace, Debug, Info, Warn, Error and Fatal.
  • Global log level Set a threshold for all components from Off up to Fatal.
  • Individual log level for each component Set each component’s (class) log level individually. This can be done at application startup or any later time.
  • Configurable log messages Each log message can be printed with log level, component’s name or line number.
  • Works with the iPhone simulator and test devices To use a test device only the ip of your system has to be set.
  • No overhead in the release version of an app SOSLog doesn’t contain any implementation when a release version is build.
  • SOS max features

here is how you can use it in your project:

The easiest way copy all the source files into your project, yes i know!!! … ”it should be avoided when possible since it’s inherently redundant and contrary to the goal of keeping “common code” modular and atomic. ” for those people you can go here and here. XD

  • Download source codes form here.
  • create a new View-Based Application project in xcode and name it: SOSLogDemo.
  • in your project create a new group, name it  SOSLog.
  • inside this group add AbstractSocket.h, AbstractSocket.m, Socket.h, Socket.m, SOSLog.h and SOSLog.m.

  • click Project -> Edit Project Settings.
  • click the build tab.
  • SOSLOGGING boolean variable has to be defined for use when preprocessing. Preprocessor Macro = SOSLOGGING=1 for within the debug configurtion Preprocessor Macro = SOSLOGGING=0 for within the release configuration

Testing SOSLog

  • import SOSlog.h in to SOSLogDemoAppDelegate.m.
  • repleace the function applicationDidFinishLaunchingWithOptions with this:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {    
    
      // configure logging
      [SOSLog showLogLevel:YES andComponentName:YES andLineNumber:YES];
      [SOSLog setGlobalLogLevel:sos_Trace];
      //[SOSLog setIP:@"192.168.178.20"];
    
      // each component has to be enabled through its filename
      [SOSLog setLogLevel:sos_Trace forComponent:@__FILE__]; // this file's name
      [SOSLog setLogLevel:sos_Trace forComponent:@"SOSLogDemoViewController.m"];
    
      log(sos_Trace, @"I'm a trace log");
      log(sos_Info, @"One more info");
      log(sos_Debug, @"You could also use %i instead of sos_Debug", 4);
      log(sos_Warn, @"It's getting more serious");
      log(sos_Error, @"%i is equal to sos_Error", 2);
      log(sos_Fatal, @"Better not getting a lot of these ...");
    
        // Override point for customization after application launch.
    
        // Add the view controller's view to the window and display.
        [window addSubview:viewController.view];
        [window makeKeyAndVisible];
    
        return YES;
    }
  • import SOSlog.h in to SOSLogDemoViewController.m
  • repleace the function viewDidLoad with this:
1
2
3
4
5
- (void)viewDidLoad {
        [super viewDidLoad];
        log(sos_Info, @"viewDidLod");
        log(sos_Trace, @"viewDidLoad");
    }

notice that you should enable each component.

    [SOSLog setLogLevel:sos_Trace forComponent:@__FILE__]; // this file's name
    [SOSLog setLogLevel:sos_Trace forComponent:@"SOSLogDemoViewController.m"];

when you compile and run, you should see something like this:

as you can see, it’s very easy to get SOSLog working in your project.

SOSLogDemo Project download. SOSLog component for Objective-C download. SOS Platform independent (WIN/MAC/Linux) download. SOS Mac OS X image download.

Comments