Or you can roll your own if you like to (as I do, since my code need to be ported across OS X and GNUstep and from time to time, iOS even).
Here is what I do:
#ifndef NDEBUG void _MKLog(const char *, int, const NSString *, …) __attribute__((format(NSString, 3, 4)); #define MKLog(fmt, …) _MKLog(__FILE__, __LINE__, fmt, ##__VA_ARGS__) #endif
And it prints things like this:
2015-02-20 14:15:27.2040+0800 [2024:pthread 0x20c test.m:14]: This is a debug message from a unnamed dispatch queue or thread. 2015-02-20 14:15:27.2040+0800 [2024:NSThread thread name test.m:14]: This is a debug message from a named thread. 2015-02-20 14:15:27.2040+0800 [2024:dispatch_queue_t queue name test.m:14]: This is a debug message from a named dispatch queue.
On 20 Feb 2015, at 19:32, Amr Aboelela <amraboelela@gmail.com> wrote: NSLogv(NSString* format, va_list args)
...
/*prefix = [NSString
stringWithFormat: @"%@ %@[%d] ",
[[NSCalendarDate calendarDate]
descriptionWithCalendarFormat: @"%Y-%m-%d %H:%M:%S.%F"],
[[NSProcessInfo processInfo] processName],
pid];*/
prefix = [NSString
stringWithFormat: @"%@ %@[%d-%x] ",
[[NSCalendarDate calendarDate] descriptionWithCalendarFormat: @"%M:%S.%F"],
[[NSProcessInfo processInfo] processName],
pid, (unsigned int)pthread_self()];
...
}
Instead of printing today date and hour which is useless for a developer, print the current thread id: (unsigned int)pthread_self()
Well, the timestamp is highly useful for most people, but perhpas more importantly we try to be compatible with Apple's implementation.However, there's a user default called GSLogThread (near the start of the base library documentation ... you can find it online at http://www.gnustep.org/resources/documentation/Developer/Base/Reference/index.html), which you can set to extend the normal log format with a thread ID. This is quite useful for debugging multithreaded programs.In addition, if you look at NSLog() in your local base library documentation, you will find a whole selection of things you can use to customise NSLog() behavior and also support various formas of debug logging._______________________________________________Discuss-gnustep mailing listDiscuss-gnustep@gnu.orghttps://lists.gnu.org/mailman/listinfo/discuss-gnustep
|