logs: use new liblinphone logs API

parent cb62b4cf
......@@ -573,10 +573,10 @@ static void dump_section(const char *section, void *data) {
#pragma mark - Logs Functions handlers
static void linphone_iphone_log_user_info(struct _LinphoneCore *lc, const char *message) {
linphone_iphone_log_handler(ORTP_MESSAGE, message, NULL);
linphone_iphone_log_handler(NULL, ORTP_MESSAGE, message, NULL);
}
static void linphone_iphone_log_user_warning(struct _LinphoneCore *lc, const char *message) {
linphone_iphone_log_handler(ORTP_WARNING, message, NULL);
linphone_iphone_log_handler(NULL, ORTP_WARNING, message, NULL);
}
#pragma mark - Display Status Functions
......@@ -1439,7 +1439,6 @@ static BOOL libStarted = FALSE;
LOGI(@"linphonecore is already created");
return;
}
linphone_core_set_log_collection_path([[LinphoneManager cacheDirectory] UTF8String]);
[Log enableLogs:[self lpConfigBoolForKey:@"debugenable_preference"]];
connectivity = none;
......
......@@ -19,13 +19,12 @@
#import "LinphoneManager.h"
#define APP_LVL 1 << 7
#define LOGV(level, ...) [Log log:APP_LVL & level file:__FILE__ line:__LINE__ format:__VA_ARGS__]
#define LOGD(...) LOGV(APP_LVL | ORTP_DEBUG, __VA_ARGS__)
#define LOGI(...) LOGV(APP_LVL | ORTP_MESSAGE, __VA_ARGS__)
#define LOGW(...) LOGV(APP_LVL | ORTP_WARNING, __VA_ARGS__)
#define LOGE(...) LOGV(APP_LVL | ORTP_ERROR, __VA_ARGS__)
#define LOGF(...) LOGV(APP_LVL | ORTP_FATAL, __VA_ARGS__)
#define LOGV(level, ...) [Log log:level file:__FILE__ line:__LINE__ format:__VA_ARGS__]
#define LOGD(...) LOGV(ORTP_DEBUG, __VA_ARGS__)
#define LOGI(...) LOGV(ORTP_MESSAGE, __VA_ARGS__)
#define LOGW(...) LOGV(ORTP_WARNING, __VA_ARGS__)
#define LOGE(...) LOGV(ORTP_ERROR, __VA_ARGS__)
#define LOGF(...) LOGV(ORTP_FATAL, __VA_ARGS__)
@interface Log : NSObject {
}
......@@ -33,5 +32,5 @@
+ (void)log:(OrtpLogLevel)severity file:(const char *)file line:(int)line format:(NSString *)format, ...;
+ (void)enableLogs:(BOOL)enabled;
void linphone_iphone_log_handler(int lev, const char *fmt, va_list args);
void linphone_iphone_log_handler(const char *domain, OrtpLogLevel lev, const char *fmt, va_list args);
@end
\ No newline at end of file
......@@ -21,42 +21,45 @@
@implementation Log
#define FILESIZE 17
#define DOMAIN_SIZE 3
+ (NSString *)cacheDirectory {
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES);
NSString *cachePath = [paths objectAtIndex:0];
BOOL isDir = NO;
NSError *error;
// cache directory must be created if not existing
if (![[NSFileManager defaultManager] fileExistsAtPath:cachePath isDirectory:&isDir] && isDir == NO) {
[[NSFileManager defaultManager] createDirectoryAtPath:cachePath
withIntermediateDirectories:NO
attributes:nil
error:&error];
}
return cachePath;
}
+ (void)log:(OrtpLogLevel)severity file:(const char *)file line:(int)line format:(NSString *)format, ... {
va_list args;
va_start(args, format);
NSString *str = [[NSString alloc] initWithFormat:format arguments:args];
const char *utf8str = [str cStringUsingEncoding:NSString.defaultCStringEncoding];
int filesize = 20;
const char *filename = strchr(file, '/') ? strrchr(file, '/') + 1 : file;
char levelC = 'U'; // undefined
if ((severity & ORTP_FATAL) != 0) {
levelC = 'F';
} else if ((severity & ORTP_ERROR) != 0) {
levelC = 'E';
} else if ((severity & ORTP_WARNING) != 0) {
levelC = 'W';
} else if ((severity & ORTP_MESSAGE) != 0) {
levelC = 'I';
} else if ((severity & ORTP_DEBUG) != 0) {
levelC = 'D';
}
if ((severity & ORTP_DEBUG) != 0) {
// 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("%c %*s:%3d - %s", levelC, filesize, filename + MAX((int)strlen(filename) - filesize, 0), line,
utf8str);
ortp_debug("%*s:%-4d/%s", FILESIZE, filename + MAX((int)strlen(filename) - FILESIZE, 0), line, utf8str);
} else {
// we want application logs to be always enabled (except debug ones) so use | ORTP_ERROR extra mask
ortp_log(severity | ORTP_ERROR, "%c %*s:%3d - %s", levelC, filesize,
filename + MAX((int)strlen(filename) - filesize, 0), line, utf8str);
ortp_log(severity, "%*s:%-4d/%s", FILESIZE, filename + MAX((int)strlen(filename) - FILESIZE, 0), line, utf8str);
}
va_end(args);
}
+ (void)enableLogs:(BOOL)enabled {
linphone_core_enable_logs_with_cb((OrtpLogFunc)linphone_iphone_log_handler);
linphone_core_set_log_collection_path([self cacheDirectory].UTF8String);
linphone_core_enable_log_collection(enabled);
linphone_core_enable_logs_with_cb(linphone_iphone_log_handler);
if (enabled) {
NSLog(@"Enabling debug logs");
linphone_core_set_log_level(ORTP_DEBUG);
......@@ -64,30 +67,33 @@
NSLog(@"Disabling debug logs");
linphone_core_set_log_level(ORTP_ERROR);
}
linphone_core_enable_log_collection(enabled);
ortp_set_log_level_mask("ios", ORTP_DEBUG | ORTP_MESSAGE | ORTP_WARNING | ORTP_ERROR | ORTP_FATAL);
}
#pragma mark - Logs Functions callbacks
void linphone_iphone_log_handler(int lev, const char *fmt, va_list args) {
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];
NSString *lvl = @"";
if ((lev & APP_LVL) == 0) {
if ((lev & ORTP_FATAL) != 0) {
lvl = @"F ";
} else if ((lev & ORTP_ERROR) != 0) {
lvl = @"E ";
} else if ((lev & ORTP_WARNING) != 0) {
lvl = @"W ";
} else if ((lev & ORTP_MESSAGE) != 0) {
lvl = @"I ";
} else if (((lev & ORTP_TRACE) != 0) || ((lev & ORTP_DEBUG) != 0)) {
lvl = @"D ";
}
if ((lev & ORTP_FATAL) != 0) {
lvl = @"F";
} else if ((lev & ORTP_ERROR) != 0) {
lvl = @"E";
} else if ((lev & ORTP_WARNING) != 0) {
lvl = @"W";
} else if ((lev & ORTP_MESSAGE) != 0) {
lvl = @"I";
} else if (((lev & ORTP_TRACE) != 0) || ((lev & ORTP_DEBUG) != 0)) {
lvl = @"D";
}
if (!domain)
domain = "liblinphone";
// since \r are interpreted like \n, avoid double new lines when logging network packets (belle-sip)
NSLog(@"%@%@", lvl, [formatedString stringByReplacingOccurrencesOfString:@"\r\n" withString:@"\n"]);
// output format is like: I/ios/some logs. We truncate domain to **exactly** DOMAIN_SIZE characters to have
// fixed-length aligned logs
NSLog(@"%@/%*.*s/%@", lvl, DOMAIN_SIZE, DOMAIN_SIZE, domain,
[formatedString stringByReplacingOccurrencesOfString:@"\r\n" withString:@"\n"]);
}
@end
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="7706" systemVersion="14D136" targetRuntime="iOS.CocoaTouch.iPad" propertyAccessControl="none" useAutolayout="YES" initialViewController="H1p-Uh-vWS">
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="9531" systemVersion="15C50" targetRuntime="iOS.CocoaTouch.iPad" propertyAccessControl="none" useAutolayout="YES" initialViewController="H1p-Uh-vWS">
<dependencies>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="7703"/>
<deployment identifier="iOS"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="9529"/>
</dependencies>
<scenes>
<!--Navigation Controller-->
......@@ -22,13 +23,13 @@
<!--Detail-->
<scene sceneID="yUG-lL-AsK">
<objects>
<viewController title="Detail" id="JEX-9P-axG" customClass="DetailView" sceneMemberID="viewController">
<viewController title="Detail" id="JEX-9P-axG" customClass="DetailTableView" sceneMemberID="viewController">
<tableView key="view" clipsSubviews="YES" contentMode="scaleToFill" alwaysBounceVertical="YES" dataMode="prototypes" style="plain" separatorStyle="default" rowHeight="44" sectionHeaderHeight="22" sectionFooterHeight="22" id="aVY-Yw-ztG">
<rect key="frame" x="0.0" y="0.0" width="703" height="768"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<color key="backgroundColor" white="1" alpha="1" colorSpace="calibratedWhite"/>
<prototypes>
<tableViewCell contentMode="scaleToFill" selectionStyle="blue" indentationWidth="10" textLabel="6lf-XI-z9S" style="IBUITableViewCellStyleDefault" id="fGk-UB-StR">
<tableViewCell contentMode="scaleToFill" selectionStyle="blue" indentationWidth="10" reuseIdentifier="testCellIdentifier" textLabel="6lf-XI-z9S" style="IBUITableViewCellStyleDefault" id="fGk-UB-StR">
<rect key="frame" x="0.0" y="86" width="703" height="44"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
<tableViewCellContentView key="contentView" opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center" tableViewCell="fGk-UB-StR" id="oMv-Vp-OY1">
......@@ -36,7 +37,7 @@
<autoresizingMask key="autoresizingMask"/>
<subviews>
<label opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="left" text="Title" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" id="6lf-XI-z9S">
<rect key="frame" x="15" y="0.0" width="673" height="43"/>
<rect key="frame" x="35" y="0.0" width="633" height="43"/>
<autoresizingMask key="autoresizingMask"/>
<fontDescription key="fontDescription" type="system" pointSize="18"/>
<color key="textColor" cocoaTouchSystemColor="darkTextColor"/>
......@@ -46,6 +47,7 @@
</tableViewCellContentView>
</tableViewCell>
</prototypes>
<sections/>
</tableView>
<toolbarItems/>
<navigationItem key="navigationItem" title="Detail" id="mOI-FS-AaM"/>
......@@ -125,9 +127,4 @@
<point key="canvasLocation" x="-366" y="248"/>
</scene>
</scenes>
<simulatedMetricsContainer key="defaultSimulatedMetrics">
<simulatedStatusBarMetrics key="statusBar"/>
<simulatedOrientationMetrics key="orientation"/>
<simulatedScreenMetrics key="destination"/>
</simulatedMetricsContainer>
</document>
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="7706" systemVersion="14D136" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" initialViewController="rS3-R9-Ivy">
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="9531" systemVersion="15C50" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" initialViewController="rS3-R9-Ivy">
<dependencies>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="7703"/>
<deployment identifier="iOS"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="9529"/>
</dependencies>
<scenes>
<!--Navigation Controller-->
......@@ -65,7 +66,7 @@
<!--Detail-->
<scene sceneID="Cn3-H9-jdl">
<objects>
<viewController title="Detail" id="Ah7-4n-0Wa" customClass="DetailView" sceneMemberID="viewController">
<viewController title="Detail" id="Ah7-4n-0Wa" customClass="DetailTableView" sceneMemberID="viewController">
<tableView key="view" clipsSubviews="YES" contentMode="scaleToFill" alwaysBounceVertical="YES" dataMode="prototypes" style="plain" separatorStyle="default" rowHeight="44" sectionHeaderHeight="22" sectionFooterHeight="22" id="HbK-cV-Nw3">
<rect key="frame" x="0.0" y="0.0" width="320" height="568"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
......@@ -97,9 +98,4 @@
<point key="canvasLocation" x="1002" y="78"/>
</scene>
</scenes>
<simulatedMetricsContainer key="defaultSimulatedMetrics">
<simulatedStatusBarMetrics key="statusBar"/>
<simulatedOrientationMetrics key="orientation"/>
<simulatedScreenMetrics key="destination" type="retina4"/>
</simulatedMetricsContainer>
</document>
......@@ -21,7 +21,7 @@ typedef NS_ENUM(int, TestState) { TestStateIdle, TestStatePassed, TestStateInPro
@end
@interface DetailView : UITableViewController
@interface DetailTableView : UITableViewController
@property(strong, nonatomic) NSString *detailItem;
......
......@@ -6,7 +6,7 @@
//
//
#import "DetailView.h"
#import "DetailTableView.h"
#import "MasterView.h"
#import "LogsView.h"
#include "linphone/liblinphone_tester.h"
......@@ -36,7 +36,7 @@ static NSString *const kAllTestsName = @"Run All tests";
@end
@interface DetailView () {
@interface DetailTableView () {
NSMutableArray *_tests;
BOOL in_progress;
}
......@@ -44,7 +44,7 @@ static NSString *const kAllTestsName = @"Run All tests";
- (void)configureView;
@end
@implementation DetailView
@implementation DetailTableView
#pragma mark - Managing the detail item
......@@ -113,7 +113,11 @@ static NSString *const kAllTestsName = @"Run All tests";
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"testCellIdentifier" forIndexPath:indexPath];
static NSString *kCellId = @"testCellIdentifier";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:kCellId forIndexPath:indexPath];
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:kCellId];
}
TestItem *test = _tests[indexPath.row];
cell.textLabel.text = [NSString stringWithFormat:@"%@/%@", test.suite, test.name];
......
......@@ -36,6 +36,8 @@
<array>
<string>armv7</string>
</array>
<key>UIRequiresFullScreen</key>
<true/>
<key>UIStatusBarTintParameters</key>
<dict>
<key>UINavigationBar</key>
......
......@@ -11,10 +11,10 @@
extern NSMutableArray *lastLogs;
extern NSString *const kLogsUpdateNotification;
@class DetailView;
@class DetailTableView;
@interface MasterView : UITableViewController
@property(strong, nonatomic) DetailView *detailViewController;
@property(strong, nonatomic) DetailTableView *detailViewController;
@end
......@@ -8,7 +8,7 @@
#import "MasterView.h"
#import "LogsView.h"
#import "DetailView.h"
#import "DetailTableView.h"
#include "linphone/liblinphone_tester.h"
#include "mediastreamer2/msutils.h"
......@@ -40,15 +40,18 @@ NSString *const kLogsUpdateNotification = @"kLogsUpdateNotification";
- (void)setupLogging {
lastLogs = [[NSMutableArray alloc] initWithCapacity:kLastLogsCapacity];
logsBuffer = [NSMutableArray arrayWithCapacity:kLogsBufferCapacity];
[Log enableLogs:YES];
}
linphone_core_set_log_level(ORTP_MESSAGE);
linphone_core_set_log_handler((OrtpLogFunc)linphone_iphone_log_handler);
void tester_logs_handler(int level, const char *fmt, va_list args) {
linphone_iphone_log_handler(NULL, level, fmt, args);
}
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
self.detailViewController = (DetailView *)[[self.splitViewController.viewControllers lastObject] topViewController];
self.detailViewController =
(DetailTableView *)[[self.splitViewController.viewControllers lastObject] topViewController];
[self setupLogging];
......@@ -56,7 +59,7 @@ NSString *const kLogsUpdateNotification = @"kLogsUpdateNotification";
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
documentPath = [paths objectAtIndex:0];
bc_tester_init((void (*)(int, const char *fm, va_list))linphone_iphone_log_handler, ORTP_MESSAGE, ORTP_ERROR);
bc_tester_init(tester_logs_handler, ORTP_MESSAGE, ORTP_ERROR);
liblinphone_tester_add_suites();
bc_tester_set_resource_dir_prefix([bundlePath UTF8String]);
......
{
"info" : {
"version" : 1,
"author" : "xcode"
}
}
\ No newline at end of file
......@@ -10,11 +10,21 @@
"size" : "29x29",
"scale" : "2x"
},
{
"idiom" : "iphone",
"size" : "29x29",
"scale" : "3x"
},
{
"idiom" : "iphone",
"size" : "40x40",
"scale" : "2x"
},
{
"idiom" : "iphone",
"size" : "40x40",
"scale" : "3x"
},
{
"idiom" : "iphone",
"size" : "57x57",
......@@ -84,6 +94,11 @@
"idiom" : "ipad",
"size" : "76x76",
"scale" : "2x"
},
{
"idiom" : "ipad",
"size" : "83.5x83.5",
"scale" : "2x"
}
],
"info" : {
......
{
"images" : [
{
"idiom" : "iphone",
"scale" : "1x",
"orientation" : "portrait"
},
{
"idiom" : "iphone",
"scale" : "2x",
"orientation" : "portrait"
},
{
"orientation" : "portrait",
"idiom" : "iphone",
"subtype" : "retina4",
"scale" : "2x"
},
{
"orientation" : "portrait",
"idiom" : "iphone",
"minimum-system-version" : "7.0",
"scale" : "2x"
},
{
"orientation" : "portrait",
"idiom" : "iphone",
"minimum-system-version" : "7.0",
"subtype" : "retina4",
"scale" : "2x"
},
{
"orientation" : "portrait",
"idiom" : "ipad",
"extent" : "to-status-bar",
"scale" : "1x"
},
{
"orientation" : "portrait",
"idiom" : "ipad",
"extent" : "to-status-bar",
"scale" : "2x"
},
{
"orientation" : "landscape",
"idiom" : "ipad",
"extent" : "to-status-bar",
"scale" : "1x"
},
{
"orientation" : "landscape",
"idiom" : "ipad",
"extent" : "to-status-bar",
"scale" : "2x"
},
{
"orientation" : "portrait",
"idiom" : "ipad",
"minimum-system-version" : "7.0",
"extent" : "full-screen",
"scale" : "1x"
},
{
"orientation" : "portrait",
"idiom" : "ipad",
"minimum-system-version" : "7.0",
"extent" : "full-screen",
"scale" : "2x"
},
{
"orientation" : "landscape",
"idiom" : "ipad",
"minimum-system-version" : "7.0",
"extent" : "full-screen",
"scale" : "1x"
},
{
"orientation" : "landscape",
"idiom" : "ipad",
"minimum-system-version" : "7.0",
"extent" : "full-screen",
"scale" : "2x"
}
],
"info" : {
"version" : 1,
"author" : "xcode"
}
}
\ No newline at end of file
......@@ -30,11 +30,14 @@
return [[testString componentsSeparatedByCharactersInSet:charactersToRemove] componentsJoinedByString:@"_"];
}
+ (void)initialize {
void tester_logs_handler(int level, const char *fmt, va_list args) {
linphone_iphone_log_handler(NULL, level, fmt, args);
}
+ (void)initialize {
static char *bundle = NULL;
static char *documents = NULL;
bc_tester_init((void (*)(int, const char *fm, va_list))linphone_iphone_log_handler, ORTP_MESSAGE, ORTP_ERROR);
bc_tester_init(tester_logs_handler, ORTP_MESSAGE, ORTP_ERROR);
liblinphone_tester_add_suites();
NSString *bundlePath = [[NSBundle mainBundle] bundlePath];
......
......@@ -48,7 +48,6 @@
- (void)beforeEach {
[[LinphoneManager instance] lpConfigSetInt:NO forKey:@"animations_preference"];
linphone_core_set_log_level(ORTP_MESSAGE);
}
- (NSString *)me {
......
This diff is collapsed.
linphone @ 8508f543
Subproject commit 67f9bd2068ab6d040ddadd4209a538aef99a893a
Subproject commit 8508f5435738598b646b37fc5ecb951ecd000281
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment