Advertise here




Advertise here

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

BTITrackingLogs

BrianSlickBrianSlick Treadmill Desk NinjaPosts: 10,670Tutorial Authors, Registered Users @ @ @ @ @ @ @ @
GitHub repos for some related projects:

BTITrackingLogs
BTICommentTrackingLogs
BTIUncommentTrackingLogs
BTIRemoveTrackingLogs

I have written about BTITrackingLogs previously and nothing there has really changed since I last wrote about it. The others are all new.

Each project builds an Automator action. This action can then be used in an Automator Workflow to create a service. In this case, highlight some text, run the service, get new text. These are intended for Xcode use, but all they care about is text so they can be used anywhere.

I've been using BTITrackingLogs for a long time, and over that time have encountered enough need for the others that I finally got around to writing them. So the general idea is that you start with a random method:
- (void)rewardForFinishingHomework
{
    BOOL didDoHomework = [self isHomeworkFinished];

    if (!didDoHomework)
    {
        return;
    }

    [self eatDessert];
}

BTITrackingLogs

Double-click either brace {} to select the method. Running the BTITrackingLogs service will give you this:
- (void)rewardForFinishingHomework
{
    BTITrackingLog(@>>> Entering <%p> %s <<<, self, __PRETTY_FUNCTION__);

    BOOL didDoHomework = [self isHomeworkFinished];

    if (!didDoHomework)
    {
        BTITrackingLog(@<<< Leaving  <%p> %s >>> EARLY - <reason not specified>, self, __PRETTY_FUNCTION__);
        return;
    }

    [self eatDessert];

    BTITrackingLog(@<<< Leaving  <%p> %s >>>, self, __PRETTY_FUNCTION__);
}

Might want to tweak the 'EARLY' one to be more explicit:
BTITrackingLog(@<<< Leaving  <%p> %s >>> EARLY - Didn't do homework, self, __PRETTY_FUNCTION__);

This will produce console output like this when run:
>>> Entering <0x833a1d0> -[RottenKid rewardForFinishingHomework] <<<
<<< Leaving  <0x833a1d0> -[RottenKid rewardForFinishingHomework] >>>
Or
>>> Entering <0x833a1d0> -[RottenKid rewardForFinishingHomework] <<<
<<< Leaving  <0x833a1d0> -[RottenKid rewardForFinishingHomework] >>> EARLY - Didn't do homework

Now you have a nice history of what your app did. Very handy for debugging. Very handy when the person running the app isn't a developer, and they can give you this information after-the-fact.

And we come to the new stuff...

BTICommentTrackingLogs

You're working on a different problem, and don't really care for these particular logs at the moment. Highlight as much text as you want, could be the entire file. Running the BTICommentTrackingLogs will give you this:
- (void)rewardForFinishingHomework
{
    //BTITrackingLog(@>>> Entering <%p> %s <<<, self, __PRETTY_FUNCTION__);

    BOOL didDoHomework = [self isHomeworkFinished];

    if (!didDoHomework)
    {
        //BTITrackingLog(@<<< Leaving  <%p> %s >>> EARLY - <reason not specified>, self, __PRETTY_FUNCTION__);
        return;
    }

    [self eatDessert];

    //BTITrackingLog(@<<< Leaving  <%p> %s >>>, self, __PRETTY_FUNCTION__);
}

Nice and easy to shut them up, and you don't have to run around manually commenting a bunch of disconnected lines.

BTIUncommentTrackingLogs

We've solved the other problem and would like to re-enable the logs. Highlight as much text as you want, could be the entire file. Running the BTIUncommentTrackingLogs service will get you back to where you started:
- (void)rewardForFinishingHomework
{
    BTITrackingLog(@>>> Entering <%p> %s <<<, self, __PRETTY_FUNCTION__);

    BOOL didDoHomework = [self isHomeworkFinished];

    if (!didDoHomework)
    {
        BTITrackingLog(@<<< Leaving  <%p> %s >>> EARLY - <reason not specified>, self, __PRETTY_FUNCTION__);
        return;
    }

    [self eatDessert];

    BTITrackingLog(@<<< Leaving  <%p> %s >>>, self, __PRETTY_FUNCTION__);
}

BTIRemoveTrackingLogs

This whole time, you've been working on someone else's project. And they don't use BTITrackingLogs. You are now ready to commit your change, but don't want these logs included. Highlight as much text as you want, could be the entire file. Running the BTIRemoveTrackingLogs service will take you back to the original, unmolested state:
- (void)rewardForFinishingHomework
{
    BOOL didDoHomework = [self isHomeworkFinished];

    if (!didDoHomework)
    {
        // bslick: Spec change. Punish if homework isn't finished.
        [self goSitInTheCorner];
    
        return;
    }

    [self eatDessert];
}

So that's pretty much it. Add them, comment them, uncomment them, and if necessary remove them. The installation and creation instructions are in the README for each one.
Professional iOS App Development. Available for hire.
BriTer Ideas LLC - WWW | Facebook | Twitter | LinkedIn

BTIKit | BTICoreDataKit | SlickShopper 2 | Leave a PayPal donation

Replies

  • BrianSlickBrianSlick Treadmill Desk Ninja Posts: 10,670Tutorial Authors, Registered Users @ @ @ @ @ @ @ @
    I recently gave a presentation on making these Automator actions, and based on audience feedback I gained a couple tips and was inspired to dig deeper into the capabilities. So BTITrackingLogs has been updated to Version 3.

    First up:

    action_screenshot.png

    A user interface! With options! I didn't know how to do this before, now I do, so here you go. You can now choose between the 2 kinds of log prefixes that I generally care about, or if you want to provide your own, you can. If course you could have done this before by tweaking the code, but now you don't have to.

    Next, smarter indenting! Previous versions hard-coded either spaces or tabs. Now it will scan the text selection, determine whether you are using spaces or tabs, and then will use the appropriate characters for indenting the logs.

    Lastly, for the "leaving early" logs, the placeholder <reason not specified> text has been tweaked so that Xcode will allow you to tab-select it, with the balloon-y text like it does for parameters. This is accomplished by simply adding a couple of pound signs: <#reason not specified#>. Yay, audience feedback!

    The project structure was rearranged, there is only a single action target now since the UI allows for options, and the action details now looks nicer in Automator.

    Enjoy.
    Professional iOS App Development. Available for hire.
    BriTer Ideas LLC - WWW | Facebook | Twitter | LinkedIn

    BTIKit | BTICoreDataKit | SlickShopper 2 | Leave a PayPal donation
Sign In or Register to comment.