This commit is contained in:
lawrencelomax 2016-02-03 11:23:14 +00:00
Родитель da9e7b01c1
Коммит 89f73ff62a
5 изменённых файлов: 44 добавлений и 24 удалений

Просмотреть файл

@ -18,7 +18,6 @@
@interface FBSimulatorLoggingEventSink ()
@property (nonatomic, strong, readonly) id<FBSimulatorLogger> logger;
@property (nonatomic, copy, readonly) NSString *prefix;
@end
@ -28,17 +27,16 @@
+ (instancetype)withSimulator:(FBSimulator *)simulator logger:(id<FBSimulatorLogger>)logger
{
return [[self alloc] initWithPrefix:[NSString stringWithFormat:@"%@: ", simulator.udid] logger:logger.info];
return [[self alloc] initWithLogger:[logger withPrefix:[NSString stringWithFormat:@"%@:", simulator.udid]]];
}
- (instancetype)initWithPrefix:(NSString *)prefix logger:(id<FBSimulatorLogger>)logger
- (instancetype)initWithLogger:(id<FBSimulatorLogger>)logger
{
self = [super init];
if (!self) {
return nil;
}
_prefix = prefix;
_logger = logger;
return self;
@ -48,62 +46,62 @@
- (void)containerApplicationDidLaunch:(FBProcessInfo *)applicationProcess
{
[self.logger logFormat:@"%@Container Application Did Launch => %@", self.prefix, applicationProcess.shortDescription];
[self.logger logFormat:@"Container Application Did Launch => %@", applicationProcess.shortDescription];
}
- (void)containerApplicationDidTerminate:(FBProcessInfo *)applicationProcess expected:(BOOL)expected
{
[self.logger logFormat:@"%@Container Application Did Terminate => %@ Expected %d", self.prefix, applicationProcess.shortDescription, expected];
[self.logger logFormat:@"Container Application Did Terminate => %@ Expected %d", applicationProcess.shortDescription, expected];
}
- (void)framebufferDidStart:(FBSimulatorFramebuffer *)framebuffer
{
[self.logger logFormat:@"%@Framebuffer Did Start => %@", self.prefix, framebuffer];
[self.logger logFormat:@"Framebuffer Did Start => %@", framebuffer];
}
- (void)framebufferDidTerminate:(FBSimulatorFramebuffer *)framebuffer expected:(BOOL)expected
{
[self.logger logFormat:@"%@Framebuffer Did Terminate => %@ Expected %d", self.prefix, framebuffer, expected];
[self.logger logFormat:@"Framebuffer Did Terminate => %@ Expected %d", framebuffer, expected];
}
- (void)simulatorDidLaunch:(FBProcessInfo *)launchdSimProcess
{
[self.logger logFormat:@"%@Simulator Did launch => %@", self.prefix, launchdSimProcess.shortDescription];
[self.logger logFormat:@"Simulator Did launch => %@", launchdSimProcess.shortDescription];
}
- (void)simulatorDidTerminate:(FBProcessInfo *)launchdSimProcess expected:(BOOL)expected
{
[self.logger logFormat:@"%@Simulator Did Terminate => %@ Expected %d", self.prefix, launchdSimProcess.shortDescription, expected];
[self.logger logFormat:@"Simulator Did Terminate => %@ Expected %d", launchdSimProcess.shortDescription, expected];
}
- (void)agentDidLaunch:(FBAgentLaunchConfiguration *)launchConfig didStart:(FBProcessInfo *)agentProcess stdOut:(NSFileHandle *)stdOut stdErr:(NSFileHandle *)stdErr
{
[self.logger logFormat:@"%@Agent Did Launch => %@", self.prefix, agentProcess.shortDescription];
[self.logger logFormat:@"Agent Did Launch => %@", agentProcess.shortDescription];
}
- (void)agentDidTerminate:(FBProcessInfo *)agentProcess expected:(BOOL)expected
{
[self.logger logFormat:@"%@Agent Did Terminate => Expected %d %@ ", self.prefix, expected, agentProcess.shortDescription];
[self.logger logFormat:@"Agent Did Terminate => Expected %d %@", expected, agentProcess.shortDescription];
}
- (void)applicationDidLaunch:(FBApplicationLaunchConfiguration *)launchConfig didStart:(FBProcessInfo *)applicationProcess stdOut:(NSFileHandle *)stdOut stdErr:(NSFileHandle *)stdErr
{
[self.logger logFormat:@"%@Application Did Launch => %@", self.prefix, applicationProcess.shortDescription];
[self.logger logFormat:@"Application Did Launch => %@", applicationProcess.shortDescription];
}
- (void)applicationDidTerminate:(FBProcessInfo *)applicationProcess expected:(BOOL)expected
{
[self.logger logFormat:@"%@Application Did Terminate => Expected %d %@", self.prefix, expected, applicationProcess.shortDescription];
[self.logger logFormat:@"Application Did Terminate => Expected %d %@", expected, applicationProcess.shortDescription];
}
- (void)diagnosticAvailable:(FBDiagnostic *)diagnostic
{
[self.logger logFormat:@"%@Log Available => %@", self.prefix, diagnostic.shortDescription];
[self.logger logFormat:@"Log Available => %@", diagnostic.shortDescription];
}
- (void)didChangeState:(FBSimulatorState)state
{
[self.logger logFormat:@"%@Did Change State => %@", self.prefix, [FBSimulator stateStringFromSimulatorState:state]];
[self.logger logFormat:@"Did Change State => %@", [FBSimulator stateStringFromSimulatorState:state]];
}
- (void)terminationHandleAvailable:(id<FBTerminationHandle>)terminationHandle

Просмотреть файл

@ -61,6 +61,7 @@ static const NSInteger FBFramebufferLogFrameFrequency = 100;
#pragma mark Initializers
+ (instancetype)withFramebufferService:(SimDeviceFramebufferService *)framebufferService hidPort:(mach_port_t)hidPort configuration:(FBSimulatorLaunchConfiguration *)launchConfiguration simulator:(FBSimulator *)simulator {
id<FBSimulatorLogger> logger = [simulator.logger withPrefix:[NSString stringWithFormat:@"%@:", simulator.udid]];
NSMutableArray *sinks = [NSMutableArray array];
BOOL useWindow = (launchConfiguration.options & FBSimulatorLaunchOptionsShowDebugWindow) == FBSimulatorLaunchOptionsShowDebugWindow;
if (useWindow) {
@ -77,9 +78,8 @@ static const NSInteger FBFramebufferLogFrameFrequency = 100;
id<FBFramebufferDelegate> delegate = [FBFramebufferCompositeDelegate withDelegates:[sinks copy]];
dispatch_queue_t queue = dispatch_queue_create("com.facebook.FBSimulatorControl.simulatorframebuffer", DISPATCH_QUEUE_SERIAL);
id<FBSimulatorLogger> logger = [simulator.logger onQueue:queue];
return [[self alloc] initWithFramebufferService:framebufferService onQueue:queue hidPort:hidPort eventSink:simulator.eventSink logger:logger delegate:delegate];
return [[self alloc] initWithFramebufferService:framebufferService onQueue:queue hidPort:hidPort eventSink:simulator.eventSink logger:[logger onQueue:queue] delegate:delegate];
}
- (instancetype)initWithFramebufferService:(SimDeviceFramebufferService *)framebufferService onQueue:(dispatch_queue_t)queue hidPort:(mach_port_t)hidPort eventSink:(id<FBSimulatorEventSink>)eventSink logger:(id<FBSimulatorLogger>)logger delegate:(id<FBFramebufferDelegate>)delegate

Просмотреть файл

@ -53,6 +53,14 @@
*/
- (id<FBSimulatorLogger>)onQueue:(dispatch_queue_t)queue;
/**
Returns a Logger that will prefix all messages with the given string
@param prefix the prefix to prepend to all messages.
@return a new Logger that will allows logging of messages on the provided queue.
*/
- (id<FBSimulatorLogger>)withPrefix:(NSString *)prefix;
@end
@interface FBSimulatorLogger : NSObject

Просмотреть файл

@ -65,12 +65,13 @@ static const char *FBASLClientDispatchLocal = "fbsimulatorcontrol_asl_client";
@property (nonatomic, strong, readonly) FBASLClientManager *clientManager;
@property (nonatomic, assign, readonly) asl_object_t client;
@property (nonatomic, assign, readonly) int currentLevel;
@property (nonatomic, copy, readonly) NSString *prefix;
@end
@implementation FBSimulatorLogger_ASL
- (instancetype)initWithClientManager:(FBASLClientManager *)clientManager client:(asl_object_t)client currentLevel:(int)currentLevel
- (instancetype)initWithClientManager:(FBASLClientManager *)clientManager client:(asl_object_t)client currentLevel:(int)currentLevel prefix:(NSString *)prefix
{
self = [super init];
if (!self) {
@ -80,12 +81,14 @@ static const char *FBASLClientDispatchLocal = "fbsimulatorcontrol_asl_client";
_clientManager = clientManager;
_client = client;
_currentLevel = currentLevel;
_prefix = prefix;
return self;
}
- (id<FBSimulatorLogger>)log:(NSString *)string
{
string = self.prefix ? [self.prefix stringByAppendingFormat:@" %@", string] : string;
asl_log(self.client, NULL, self.currentLevel, string.UTF8String, NULL);
return self;
}
@ -102,23 +105,28 @@ static const char *FBASLClientDispatchLocal = "fbsimulatorcontrol_asl_client";
- (id<FBSimulatorLogger>)info
{
return [[FBSimulatorLogger_ASL alloc] initWithClientManager:self.clientManager client:self.client currentLevel:ASL_LEVEL_INFO];
return [[FBSimulatorLogger_ASL alloc] initWithClientManager:self.clientManager client:self.client currentLevel:ASL_LEVEL_INFO prefix:self.prefix];
}
- (id<FBSimulatorLogger>)debug
{
return [[FBSimulatorLogger_ASL alloc] initWithClientManager:self.clientManager client:self.client currentLevel:ASL_LEVEL_DEBUG];
return [[FBSimulatorLogger_ASL alloc] initWithClientManager:self.clientManager client:self.client currentLevel:ASL_LEVEL_DEBUG prefix:self.prefix];
}
- (id<FBSimulatorLogger>)error
{
return [[FBSimulatorLogger_ASL alloc] initWithClientManager:self.clientManager client:self.client currentLevel:ASL_LEVEL_ERR];
return [[FBSimulatorLogger_ASL alloc] initWithClientManager:self.clientManager client:self.client currentLevel:ASL_LEVEL_ERR prefix:self.prefix];
}
- (id<FBSimulatorLogger>)onQueue:(dispatch_queue_t)queue
{
asl_object_t client = [self.clientManager clientHandleForQueue:queue];
return [[FBSimulatorLogger_ASL alloc] initWithClientManager:self.clientManager client:client currentLevel:self.currentLevel];
return [[FBSimulatorLogger_ASL alloc] initWithClientManager:self.clientManager client:client currentLevel:self.currentLevel prefix:self.prefix];
}
- (id<FBSimulatorLogger>)withPrefix:(NSString *)prefix
{
return [[FBSimulatorLogger_ASL alloc] initWithClientManager:self.clientManager client:self.client currentLevel:self.currentLevel prefix:prefix];
}
@end
@ -133,7 +141,7 @@ static const char *FBASLClientDispatchLocal = "fbsimulatorcontrol_asl_client";
int fileDescriptor = writeToStdErr ? STDERR_FILENO : 0;
FBASLClientManager *clientManager = [[FBASLClientManager alloc] initWithWritingToFileDescriptor:fileDescriptor debugLogging:debugLogging];
asl_object_t client = [clientManager clientHandleForQueue:dispatch_get_main_queue()];
logger = [[FBSimulatorLogger_ASL alloc] initWithClientManager:clientManager client:client currentLevel:ASL_LEVEL_INFO];
logger = [[FBSimulatorLogger_ASL alloc] initWithClientManager:clientManager client:client currentLevel:ASL_LEVEL_INFO prefix:nil];
});
return logger;
}

Просмотреть файл

@ -101,4 +101,10 @@
return [[JSONLogger alloc] initWithEventReporter:self.reporter currentLevel:ASL_LEVEL_ERR maxLevel:self.maxLevel dispatchToMain:dispatchToMain];
}
- (id<FBSimulatorLogger>)withPrefix:(NSString *)prefix
{
// Ignore prefixing as 'subject' will be included instead.
return self;
}
@end