Remove NSLog header - ios

Below is a typical NSLog output from the console. Can I get rid of the bold text?
2013-06-09 22:17:02.351 ProjectName[33584:907] MyWantedText
I want to cut out the console text, and compare it (by diff), to a similar log. I don't want time data etc that only will produce false positives.
Is it possible to make my own console write method, MyNsLog, if I can't alter de behavior NSLog?

for your app put this into your Prefix header:
#undef NSLog
#define NSLog(fmt, ...) printf("%s", [[NSString stringWithFormat:fmt, ##__VA_ARGS__] UTF8String])
but id actually rather leave nslog and just use another logging mechanism like ddlog or so

Simple,
NSString *text = #"Some text here";
printf("%s", [text UTF8String]);
Result,
Some text here

You can't rid of the bold text, NSLog() adds the capability to print out objects variables. Also as you can see, adds the program name, the date, the time.
You can change for another logging function like printf

Related

Unity / Objective-C: Trouble converting char* to NSString

I have what should be a dead-simple piece of code that is failing for me in strange ways.
void MediaShare(char* text, char* furl) {
NSString *status = [NSString stringWithUTF8String: text];
NSString *media = [NSString stringWithUTF8String: furl];
[[SocialShare sharedInstance] mediaShare:status media:media];
text is just a line of text for Twitter sharing, and furl is just a file location string. I am getting a crash down past this function that comes down to bad data getting passed. Putting a breakpoint at the head of this function yields the following-
Image of Xcode variable monitor
The two values look fine, although not sure if the * values that only contain the first char are a problem.
Anyway, jumping to the end, and status and media appear to be converted to hex values.
Converted to hex values?
Any ideas? To give the full story, this is a Unity plug-in. I am simply passing in two strings from Unity C# to this function.
Thanks so much.
The code looks fine so far, if the input values are well formed C char* strings that can be interpreted as an UTF-8 encoded string.
status and media being hex values at the end of the function hint that they are. Both are pointers to Objective-C objects, so this is expected. Print them to the debug console or use po status at the debug console to check their contents (it will print the result of the -description method of status which is the string content in that case).
The subsequent crash might be caused elsewhere in the code.
What's the crash's log output?

Value stored in 'parameter name' is never read in commented Macro

I'm using different Macros in order to log different sections of my app. This way I can "turn off" some of the logging using comments.
Example:
String *logValue = #"This is some log text")
and then:
NetworkLog(#"%#", logValue);
SessionLog(#"%#", logValue);
I can turn off all session logs in my app by commenting that specific Macro code and leaving the network logs active.
When I turn off that specific Macro I get an analyzer warning:
Value stored in 'logValue' is never read
How can I solve this issue?
If you mark the variable as "unused", that should prevent the warning.
__unused NSString *logValue = #"This is some log text";
or
__attribute__((unused)) NSString *logValue = #"This is some log text";

How can I print the name of the object / interface with Xcode breakpoint log?

Xcode debug log can print the method name using %B and the hit count using %H. How can I print the interface / object name using similar notation ? Preferably without the use of NSLog / debugger command.
The closest you can get is
NSLog("My file is %#", [NSString stringWithUTF8String:__FILE__]);
__PRETTY_FUNCTION__ contains the class name and method, which may suit you better than FILE.
I just found that #[self class]# log message will do the trick. I am not sure its validity on every occasion. I am using #[self class]# %B %H for my purpose. I also found this question and answer but it was not just working on Xcode 6.2.
Every Objective-C object can be printed with %#. NSLog(#"%#", someObject) will print object's description. You can override description method for your classes to provide more detailed info. Look at this note too: Improved logging in Objective-C
In the breakpoint's debugger command action, you can put:
expr printf ("[%s %s]\n", (char *)object_getClassName(self), _cmd)
This will output, e.g. [SomeClass someMethod:]
You can print anything using NSLog();
Say, for example, you have an
NSString *myString = #"qdfsqsdfqsdf";
This is an important string you would like to log, you'll just type :
NSLog(#"My important string : %#", myString);
If that is what you're asking, I'm surprised you dont' know that if you already know about %B & %H. Am I answering your question or do you need a bit more?

Disable date/process ID in xcode output

How can I remove date and process ID from output window in XCode? They only take up a lot of space without real value.
Use this macro, this will override the default behavior of NSLog,
#define NSLog(STRING, ...) printf("%s\n", [[NSString stringWithFormat:STRING, ##__VA_ARGS__] UTF8String]);

my apostrophe turns into ’

i'm trying to send the iOS device name along with the deviceToken to my server in didRegisterForRemoteNotificationsWithDeviceToken.. my device has an apostrophe in it and the request string shows as ....&name=John+Doe’s+iPhone ...
I've tried replacing "'" with "" and "’" with "" .. but neither fix it.. i assume i need to convert the encoding?
NSString *string = [[UIDevice currentDevice] name];
output-> John Doe’s iPhone
EDIT
output is from
NSLog(string);
You should never use NSLog with a user-provided string like that. NSLog expects a format string for its first argument. If it's something containing a format specifier, it will probably crash your application, and may expose a security hole if provided by an untrusted source.
Your encoding issue appears to be a bug in LLDB. Switching to GDB fixes the problem.
Wait, you're doing NSLog(string)? You need NSLog(#"%#", string)

Resources