Clean NSLog-brak znacznika czasu i nazwy programu
Prawie skończyłem czysty NSLog z tym kodem:
#define NSLog(FORMAT, ...) printf("%s\n", [[NSString stringWithFormat:FORMAT, __VA_ARGS__] UTF8String]);
To działa dobrze, jeśli robię to:
NSLog(@"Show %@ message", @"this");
Ale, nie powiedzie się, jeśli go użyję
NSLog(@"One argument");
Ponieważ __VA_ARGS__
jest niczym, więc produkuje
printf("%s\n", [[NSString stringWithFormat:@"One argument",] UTF8String]);
Więc problemem jest przecinek. Ponieważ jest to makro, {[4] } jest niczym. Więc nie mogę robić takich rzeczy jak __VA_ARGS__==nil
, ponieważ będzie produkować ==nil
i zawiedzie.
Pytanie jest proste: co robić, gdy __VA_ARGS__
jest niczym? Lub używaj przecinka tylko wtedy, gdy masz więcej argumentów.
24
Author: Albert Renshaw, 2011-09-22
1 answers
Użyj tego kodu (zwróć uwagę na Część ##
):
#define NSLog(FORMAT, ...) fprintf(stderr, "%s\n", [[NSString stringWithFormat:FORMAT, ##__VA_ARGS__] UTF8String]);
58
Author: xuzhe,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2017-12-17 14:59:58
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2017-12-17 14:59:58