krzysztofzablocki / LinkedConsole

Clickable links in your Xcode console, so you never wonder which class logged the message.
http://merowing.info
MIT License
931 stars 63 forks source link

Not working if using lastPathComponent #6

Closed kenji21 closed 8 years ago

kenji21 commented 8 years ago

Works :

#define OKLog(s,...) NSLog( @"%s:%d: %p %@/%@\n%@", __FILE__, __LINE__, self, NSStringFromClass([self class]), NSStringFromSelector(_cmd), [NSString stringWithFormat:(s), ##__VA_ARGS__] )

outputs :

2015-12-09 12:58:58.686 App[67338:2289954] /Users/kenji/source-cache/app/Classes/AppDelegate.m:73: 0x7fba8c8f3210 AppDelegate/application:didFailToRegisterForRemoteNotificationsWithError:

Don't work :

#define OKLog(s,...) NSLog( @"%@:%d: %p %@/%@\n%@", [[NSString stringWithUTF8String:__FILE__] lastPathComponent], __LINE__, self, NSStringFromClass([self class]), NSStringFromSelector(_cmd), [NSString stringWithFormat:(s), ##__VA_ARGS__] )
2015-12-09 12:57:49.728 CFFlux[66697:2287745] AppDelegate.m:73: 0x7fd418732120 AppDelegate/application:didFailToRegisterForRemoteNotificationsWithError:

The only difference between first and second OKLog define is for the first parameter which changed from __FILE__ to [[NSString stringWithUTF8String:__FILE__] lastPathComponent]

The issue is that I don't want to have the full file path in the output. But it may be difficult to find corresponding file in the project.

kenji21 commented 8 years ago

Looking at the GIF in your blog post didn't show the full path... is another plugin removing the path ?

krzysztofzablocki commented 8 years ago

ah crap I think it's same issue as #4 and it's the find that is not working, can you put a breakpoint and see if there is a workspacePath and what it's value is (NSTextStorage+Extension) injectLinksIntoLogs?

kenji21 commented 8 years ago

Looks good :

Printing description of path: "/Users/kenji/source-cache/app"

krzysztofzablocki commented 8 years ago

It's missing /Classes in the composed path though ?

kenji21 commented 8 years ago

Hmm... i've created another "blank" project, to copy the define inside and it works with lastPathComponent. I'm investigating.

krzysztofzablocki commented 8 years ago

@kenji21 when you investigate could you record:

I might have missed some case that breaks connections there

kenji21 commented 8 years ago

From line 59, got nil :

(lldb) po workspace?.valueForKeyPath("representingFilePath._pathString")
nil
kenji21 commented 8 years ago

And sometimes it's OK :

(lldb) po workspace?.valueForKeyPath("representingFilePath._pathString")
▿ Optional(/Users/kenji/source-cache/app/App.xcodeproj)
kenji21 commented 8 years ago

And then, no matches at pattern.matchesInString at NSTextStorage+Extensions:45

kenji21 commented 8 years ago

OK, i comment too quickly, the no match was due to a third party library log...

kenji21 commented 8 years ago

now it works... unbelievable

(lldb) po result "/Users/kenji/source-cache/app/App/AppDelegate.m"

krzysztofzablocki commented 8 years ago

so the point of failure looks like the workspacePath ?

kenji21 commented 8 years ago

I'm sure to have restarted xcode after having built your plugin (had the "load bundle" alert). now it works, i'll post again if it doesn't work after installing the plugin on a teammate mac.

krzysztofzablocki commented 8 years ago

@kenji21 I update the plugin, can you reinstall and give it a try, should be more stable

kenji21 commented 8 years ago

Installed on a second mac. no issue with the same project on this one. My teammate was having a suggestion : same feature from a stacktrace... (a little harder because no filename, and crash can be in a class extension)

krzysztofzablocki commented 8 years ago

@kenji21 was he running the updated version? I think this one is more stable because it fixed #4

kenji21 commented 8 years ago

was running at commit 26b60febbb77a5dd3a1bb97c6ea646e76b7da065

krzysztofzablocki commented 8 years ago

ok, try with updated, I'm closing this but if you see it happening let me know and we'll reopen

kenji21 commented 8 years ago

sure, thanks for support (and many thanks for this great plugin, vote up to have it directly inside xcode)

oldtrafford91 commented 8 years ago

how I can strip file path with only file name

kenji21 commented 8 years ago

@oldtrafford91 simply with this code : [[NSString stringWithUTF8String:__FILE__] lastPathComponent]

@krzysztofzablocki updated to current HEAD, restarted xcode, no issue.