Utils.m: properly handle UTF8 logging

This commit is contained in:
Gautier Pelloux-Prayer 2015-10-16 11:09:03 +02:00
parent f48e8122c5
commit 20fcf449fc

View file

@ -28,15 +28,17 @@
va_list args;
va_start(args, format);
NSString *str = [[NSString alloc] initWithFormat:format arguments:args];
NSStringEncoding enc = CFStringConvertEncodingToNSStringEncoding(CFStringGetSystemEncoding());
const char *utf8str = [str cStringUsingEncoding:enc];
int filesize = 20;
const char *filename = strchr(file, '/') ? strrchr(file, '/') + 1 : file;
if (severity <= ORTP_DEBUG) {
// lol: ortp_debug(XXX) can be disabled at compile time, but ortp_log(ORTP_DEBUG, xxx) will always be valid even
// not in debug build...
ortp_debug("%*s:%3d - %s", filesize, filename + MAX((int)strlen(filename) - filesize, 0), line, str.UTF8String);
ortp_debug("%*s:%3d - %s", filesize, filename + MAX((int)strlen(filename) - filesize, 0), line, utf8str);
} else {
ortp_log(severity, "%*s:%3d - %s", filesize, filename + MAX((int)strlen(filename) - filesize, 0), line,
str.UTF8String);
utf8str);
}
va_end(args);
}