初始化提交
This commit is contained in:
49
WebDriverAgentLib/Utilities/FBDebugLogDelegateDecorator.m
Normal file
49
WebDriverAgentLib/Utilities/FBDebugLogDelegateDecorator.m
Normal file
@@ -0,0 +1,49 @@
|
||||
/**
|
||||
* Copyright (c) 2015-present, Facebook, Inc.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This source code is licensed under the BSD-style license found in the
|
||||
* LICENSE file in the root directory of this source tree.
|
||||
*/
|
||||
|
||||
#import "FBDebugLogDelegateDecorator.h"
|
||||
|
||||
#import "FBLogger.h"
|
||||
#import "XCTestPrivateSymbols.h"
|
||||
|
||||
@interface FBDebugLogDelegateDecorator ()
|
||||
@property (nonatomic, strong) id<XCDebugLogDelegate> debugLogger;
|
||||
@end
|
||||
|
||||
@implementation FBDebugLogDelegateDecorator
|
||||
|
||||
+ (void)decorateXCTestLogger
|
||||
{
|
||||
FBDebugLogDelegateDecorator *decorator = [FBDebugLogDelegateDecorator new];
|
||||
id<XCDebugLogDelegate> debugLogger = XCDebugLogger();
|
||||
if ([debugLogger isKindOfClass:FBDebugLogDelegateDecorator.class]) {
|
||||
// Already decorated
|
||||
return;
|
||||
}
|
||||
decorator.debugLogger = debugLogger;
|
||||
XCSetDebugLogger(decorator);
|
||||
}
|
||||
|
||||
- (void)logDebugMessage:(NSString *)logEntry
|
||||
{
|
||||
NSString *debugLogEntry = logEntry;
|
||||
static NSString *processName;
|
||||
static dispatch_once_t onceToken;
|
||||
dispatch_once(&onceToken, ^{
|
||||
processName = [NSProcessInfo processInfo].processName;
|
||||
});
|
||||
if ([logEntry rangeOfString:[NSString stringWithFormat:@" %@[", processName]].location != NSNotFound) {
|
||||
// Ignoring "13:37:07.638 TestingApp[56374:10997466] " from log entry
|
||||
NSUInteger ignoreCharCount = [logEntry rangeOfString:@"]"].location + 2;
|
||||
debugLogEntry = [logEntry substringWithRange:NSMakeRange(ignoreCharCount, logEntry.length - ignoreCharCount)];
|
||||
}
|
||||
[FBLogger verboseLog:debugLogEntry];
|
||||
[self.debugLogger logDebugMessage:logEntry];
|
||||
}
|
||||
|
||||
@end
|
||||
Reference in New Issue
Block a user