from asl_log to os_log

This commit is contained in:
Benjamin Reis 2016-11-10 15:55:58 +01:00
parent 8d00cdbcde
commit 593d0e0be8
2 changed files with 64 additions and 23 deletions

View file

@ -19,6 +19,7 @@
#import "Log.h"
#import <asl.h>
#import <os/log.h>
@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

View file

@ -85,6 +85,12 @@
ReferencedContainer = "container:linphone.xcodeproj">
</BuildableReference>
</BuildableProductRunnable>
<EnvironmentVariables>
<EnvironmentVariable
key = "OS_ACTIVITY_MODE"
isEnabled = "YES">
</EnvironmentVariable>
</EnvironmentVariables>
<AdditionalOptions>
<AdditionalOption
key = "NSZombieEnabled"