icanzilb / MTLog

NSLog replacement for coders!
MIT License
222 stars 24 forks source link

Issue or suggested request #3

Open quique123 opened 11 years ago

quique123 commented 11 years ago

Gr8 project. I was wondering if this could somehow relate to this project but Ive always wanted, for debugging purposes, a way to keep track of a single property or variable throughout the app's lifecycle. For example, let's say I want to know each time a property self.currentLocation, is changed. Overriding setters is one way but its still messy to follow all logs in the console. This helps to know when a value is changed out from under you without you necessarily remembering what piece of coded you added where that resulted in that change.

alexshepard commented 11 years ago

Out of curiosity, couldn't you use KVO for this?

icanzilb commented 11 years ago

yup - if the property is always set through its setter it sounds like something you could easily achieve via KVO. it's not really related to logging though or?

quique123 commented 11 years ago

Well I'm just looking for a way, KVO is not it. The whole point is that looking through a huge console print out is tedious so unless something is done to the log so that it's easier to differentiate those particular logs from all other ones you have accumulated during the apps life cycle, it becomes a problem.

Sent from my iPhone

On Sep 25, 2013, at 12:40 AM, Marin Todorov notifications@github.com wrote:

yup - if the property is always set through its setter it sounds like something you could easily achieve via KVO. it's not really related to logging though or?

— Reply to this email directly or view it on GitHub.

icanzilb commented 11 years ago

ah! if you put things like this - there is a way :)

just a thought - say if you have a class "MyClass" and you want to track changes to property "prop"... Just add this method to your class:

-(void)setProp:(id)value
{
  _prop = value;
  NSLog(@"_filter:$this prop = %@", value);
}

This filter will remove everything else from the output console BUT itself. So, the effect will be that after the first time you set a value to this property, all the following output will be only:

prop = X prop = Y prop = Z etc. etc.

Now the problem is that you cannot really log which method called the property setter ... hm ... complicated task indeed ...

DanSalagean commented 11 years ago

In that case I would overload that method like this:


- (void)setProp:(id)value fromMethod:(SEL)callingMethodSignature  {

     _prop = value;
     NSLog(@"_filter:$this \r\r prop = %@ \r\r modified via method: %@ \r\r", value, NSStringFromSelector(callingMethodSignature));

}

You could use it like this:


- (void)methodFoo_inClassABC {

     [instanceOfMyClass setProp:someValue fromMethod:_cmd];

}

You could continue to overload the method, adding support for more descriptors:


- (void)setProp:(id)value fromMethod:(SEL)callingMethodSignature inClass:(Class)callingMethodClass  {

  _prop = value;
  NSLog(@"_filter:$this \r\r prop = %@ \r\r modified via method: %@ \r\r called by class:%@ \r\r", value, NSStringFromSelector(callingMethodSignature), NSStringFromClass(callingMethodClass));

}

Again, using it like this:


- (void)methodFoo_inClassABC {

     [instanceOfMyClass setProp:someValue fromMethod:_cmd inClass:[self class]];

}

Then you could selectively change your setProp calls throughout the code as you debug. Try it! I think it will work well.

icanzilb commented 11 years ago

Dan, that's a cool idea - this can generate a really informative report!

DanSalagean commented 11 years ago

Glad you like it! I just came across your project and I'm intrigued. Thanks for sharing your code :)

I'm using XcodeColors at the moment to help in my debugging, and I just cloned your repository. In the morning, I plan to test whether they are compatible.

If I get it to work, I'll make note of it here, and if I have to make any changes so that they're compatible, I'll happily submit a pull request either here or at the XcodeColors repository. Obviously, highlighting statements with custom colors helps big-time if you happen to be looking for specific log statements in the Xcode console.

Mixing that with your project would ensure that not only can you find those lines quickly via their colors, but that you will find a thorough description to go along with them as well.

icanzilb commented 11 years ago

I was already thinking of putting in XcodeColors support, but installing an xcode plugin has put me off. Using a different color was also the initial idea for the _search plugin, but I don't want to include XcodeColors as a requirement ... maybe an optional compatibility with it would be cool?

DanSalagean commented 11 years ago

Definitely would be cool.

Could easily check if it's installed with some ifdefs since XcodeColors uses #defines for XCODE_COLORS_ESCAPE macro.

I'll get on this tomorrow and I'll let you know how it goes.

icanzilb commented 11 years ago

any luck with getting colors ?

DanSalagean commented 11 years ago

Sorry for the delay -- I've been switched back to a map-based project at work and it has been eating up all my time.

I'll try to work on this over the weekend.