diff --git a/Classes/Utils/Log.m b/Classes/Utils/Log.m index afae77596..88b336174 100644 --- a/Classes/Utils/Log.m +++ b/Classes/Utils/Log.m @@ -19,6 +19,7 @@ #import "Log.h" #import +#import @implementation Log @@ -78,34 +79,68 @@ void linphone_iphone_log_handler(const char *domain, OrtpLogLevel lev, const char *fmt, va_list args) { NSString *format = [[NSString alloc] initWithUTF8String:fmt]; NSString *formatedString = [[NSString alloc] initWithFormat:format arguments:args]; - int lvl = ASL_LEVEL_NOTICE; - switch (lev) { - case ORTP_FATAL: - lvl = ASL_LEVEL_CRIT; - break; - case ORTP_ERROR: - lvl = ASL_LEVEL_ERR; - break; - case ORTP_WARNING: - lvl = ASL_LEVEL_WARNING; - break; - case ORTP_MESSAGE: - lvl = ASL_LEVEL_NOTICE; - break; - case ORTP_DEBUG: - case ORTP_TRACE: - lvl = ASL_LEVEL_INFO; - break; - case ORTP_LOGLEV_END: - return; - } + if (!domain) domain = "lib"; // since \r are interpreted like \n, avoid double new lines when logging network packets (belle-sip) // output format is like: I/ios/some logs. We truncate domain to **exactly** DOMAIN_SIZE characters to have // fixed-length aligned logs - asl_log(NULL, NULL, lvl, "%*.*s/%s", DOMAIN_SIZE, DOMAIN_SIZE, domain, - [formatedString stringByReplacingOccurrencesOfString:@"\r\n" withString:@"\n"].UTF8String); + + if (floor(NSFoundationVersionNumber) > NSFoundationVersionNumber_iOS_9_x_Max) { + os_log_t log = os_log_create("", "Notice"); + os_log_type_t type = OS_LOG_TYPE_INFO; + switch (lev) { + case ORTP_FATAL: + type = OS_LOG_TYPE_FAULT; + log = os_log_create("sip.linphone.org", "Fatal"); + break; + case ORTP_ERROR: + type = OS_LOG_TYPE_ERROR; + log = os_log_create("sip.linphone.org", "Error"); + break; + case ORTP_WARNING: + type = OS_LOG_TYPE_DEFAULT; + log = os_log_create("sip.linphone.org", "Warning"); + break; + case ORTP_MESSAGE: + type = OS_LOG_TYPE_INFO; + log = os_log_create("sip.linphone.org", "Notice"); + break; + case ORTP_DEBUG: + case ORTP_TRACE: + type = OS_LOG_TYPE_INFO; + log = os_log_create("sip.linphone.org", "Debug"); + break; + case ORTP_LOGLEV_END: + return; + } + os_log_with_type(log, type, "%{public}s/%{public}s", domain, + [formatedString stringByReplacingOccurrencesOfString:@"\r\n" withString:@"\n"].UTF8String); + } else { + int lvl = ASL_LEVEL_NOTICE; + switch (lev) { + case ORTP_FATAL: + lvl = ASL_LEVEL_CRIT; + break; + case ORTP_ERROR: + lvl = ASL_LEVEL_ERR; + break; + case ORTP_WARNING: + lvl = ASL_LEVEL_WARNING; + break; + case ORTP_MESSAGE: + lvl = ASL_LEVEL_NOTICE; + break; + case ORTP_DEBUG: + case ORTP_TRACE: + lvl = ASL_LEVEL_INFO; + break; + case ORTP_LOGLEV_END: + return; + } + asl_log(NULL, NULL, lvl, "%*.*s/%s", DOMAIN_SIZE, DOMAIN_SIZE, domain, + [formatedString stringByReplacingOccurrencesOfString:@"\r\n" withString:@"\n"].UTF8String); + } } @end diff --git a/linphone.xcodeproj/xcshareddata/xcschemes/linphone.xcscheme b/linphone.xcodeproj/xcshareddata/xcschemes/linphone.xcscheme index 01d4a2dff..87208c7a6 100644 --- a/linphone.xcodeproj/xcshareddata/xcschemes/linphone.xcscheme +++ b/linphone.xcodeproj/xcshareddata/xcschemes/linphone.xcscheme @@ -85,6 +85,12 @@ ReferencedContainer = "container:linphone.xcodeproj"> + + + +