From version < 14.1 >
edited by Admin Admin
on 2017/02/23 11:04
To version < 15.1 >
edited by Admin Admin
on 2017/05/24 09:16
< >
Change comment: There is no comment for this version

Summary

Details

Page properties
Content
... ... @@ -54,72 +54,49 @@
54 54  Here is a little example on how to manage liblinphone log into an IOS app :
55 55  
56 56  {{code language="Objective-C"}}
57 -void linphone_iphone_log_handler(const char *domain, OrtpLogLevel lev, const char *fmt, va_list args) {
58 - NSString *format = [[NSString alloc] initWithUTF8String:fmt];
59 - NSString *formatedString = [[NSString alloc] initWithFormat:format arguments:args];
57 + NSString *format = [[NSString alloc] initWithUTF8String:fmt];
58 + NSString *formatedString = [[NSString alloc] initWithFormat:format arguments:args];
59 + NSString *lvl;
60 60  
61 - if (!domain)
62 - domain = "lib";
63 - // since \r are interpreted like \n, avoid double new lines when logging network packets (belle-sip)
64 - // output format is like: I/ios/some logs. We truncate domain to **exactly** DOMAIN_SIZE characters to have
65 - // fixed-length aligned logs
66 -
67 - if (floor(NSFoundationVersionNumber) > NSFoundationVersionNumber_iOS_9_x_Max) {
68 - os_log_t log = os_log_create("subsystem", "Notice");
69 - os_log_type_t type = OS_LOG_TYPE_INFO;
70 - switch (lev) {
71 - case ORTP_FATAL:
72 - type = OS_LOG_TYPE_FAULT;
73 - log = os_log_create("subsystem", "Fatal");
74 - break;
75 - case ORTP_ERROR:
76 - type = OS_LOG_TYPE_ERROR;
77 - log = os_log_create("subsystem", "Error");
78 - break;
79 - case ORTP_WARNING:
80 - type = OS_LOG_TYPE_DEFAULT;
81 - log = os_log_create("subsystem", "Warning");
82 - break;
83 - case ORTP_MESSAGE:
84 - type = OS_LOG_TYPE_INFO;
85 - log = os_log_create("subsystem", "Notice");
86 - break;
87 - case ORTP_DEBUG:
88 - case ORTP_TRACE:
89 - type = OS_LOG_TYPE_INFO;
90 - log = os_log_create("subsystem", "Debug");
91 - break;
92 - case ORTP_LOGLEV_END:
93 - return;
94 - }
95 - os_log_with_type(log, type, "%{public}s/%{public}s", domain,
96 - [formatedString stringByReplacingOccurrencesOfString:@"\r\n" withString:@"\n"].UTF8String);
97 - } else {
98 - int lvl = ASL_LEVEL_NOTICE;
99 - switch (lev) {
100 - case ORTP_FATAL:
101 - lvl = ASL_LEVEL_CRIT;
102 - break;
103 - case ORTP_ERROR:
104 - lvl = ASL_LEVEL_ERR;
105 - break;
106 - case ORTP_WARNING:
107 - lvl = ASL_LEVEL_WARNING;
108 - break;
109 - case ORTP_MESSAGE:
110 - lvl = ASL_LEVEL_NOTICE;
111 - break;
112 - case ORTP_DEBUG:
113 - case ORTP_TRACE:
114 - lvl = ASL_LEVEL_INFO;
115 - break;
116 - case ORTP_LOGLEV_END:
117 - return;
118 - }
119 - asl_log(NULL, NULL, lvl, "%*.*s/%s", DOMAIN_SIZE, DOMAIN_SIZE, domain,
120 - [formatedString stringByReplacingOccurrencesOfString:@"\r\n" withString:@"\n"].UTF8String);
121 - }
122 -}
61 + if (!domain)
62 + domain = "lib";
63 + // since \r are interpreted like \n, avoid double new lines when logging network packets (belle-sip)
64 + // output format is like: I/ios/some logs. We truncate domain to **exactly** DOMAIN_SIZE characters to have
65 + // fixed-length aligned logs
66 + switch (lev) {
67 + case ORTP_FATAL:
68 + lvl = @"Fatal";
69 + break;
70 + case ORTP_ERROR:
71 + lvl = @"Error";
72 + break;
73 + case ORTP_WARNING:
74 + lvl = @"Warning";
75 + break;
76 + case ORTP_MESSAGE:
77 + lvl = @"Message";
78 + break;
79 + case ORTP_DEBUG:
80 + lvl = @"Debug";
81 + break;
82 + case ORTP_TRACE:
83 + lvl = @"Trace";
84 + break;
85 + case ORTP_LOGLEV_END:
86 + return;
87 + }
88 + if ([formatedString containsString:@"\n"]) {
89 + NSArray *myWords = [[formatedString stringByReplacingOccurrencesOfString:@"\r\n" withString:@"\n"]
90 + componentsSeparatedByString:@"\n"];
91 + for (int i = 0; i < myWords.count; i++) {
92 + NSString *tab = i > 0 ? @"\t" : @"";
93 + if (((NSString *)myWords[i]).length > 0) {
94 + NSLog(@"[%@] %@%@", lvl, tab, (NSString *)myWords[i]);
95 + }
96 + }
97 + } else {
98 + NSLog(@"[%@] %@", lvl, [formatedString stringByReplacingOccurrencesOfString:@"\r\n" withString:@"\n"]);
99 + }
123 123  {{/code}}
124 124  
125 125